Documente Academic
Documente Profesional
Documente Cultură
class A{
int X1,X2,X3;
public:
A(){
X1 = 1;
X2 = 2;
X3 = 3;
cout<<”Constructor of A\n”;
}
void prn(){
cout<<X1<<X2<<X3<<endl;
}
};
class B: public A{
int Y1,Y2,Y3;
public:
B(){
Y1 = 10;
Y2 = 12;
Y3 = 15;
cout<<”Constructor of B\n”;
void prn(){
cout<<Y1<<Y2<<Y3<<endl;
}
};
class C : public A {
int Z1,Z2,Z3;
public:
C() {
Z1 = 21;
Z2 = 22;
Z3 = 24;
cout<<”Constructor of C\n”;
};
1
void main() {
C ob;
}
class A {
protected:
int X;
public :
void get(int);
void get(int);
void show(int);
};
class B {
protected:
int Y;
public :
void getB(int);
void showB(int);
};
class C : public A,B {
public :
void showdata(int);
};
class A {
private : int X1;
public : int X2;
protected : int x3;
};
class B : public A {
public :
2
void fun() {
int Y1,Y2,Y3;
Y1 = X1;
Y2 = X2;
Y3 = X3;
}
};
class C : A {
public :
void f() {
int Z1,Z2,Z3;
Z1 = X1;
Z2 = X2;
Z3 = X3;
};
int main(){
int p,q,r,I,j,k;
B Obj1;
C Obj2;
P = Obj1.X1;
q = Obj1.X2;
r = Obj1.X3;
I = Obj2.X1;
j = Obj2.X2;
k = Ob21.X3;
return 0;
class Test {
char paper[20];
int Marks;
3
public:
Test()
{
strcpy (paper, Computer”);
Marks = 0;
}
Test(char P[])
{
strcpy (paper ,p);
Marks = 0;
}
Test(int M)
{
strcpy (paper,”Computer”);
Marks = m;
}
Test(char p[]), int M)
{
strcpy (Paper, P);
Marks=M;
}
};
(ii) write statements in c++ that would execute function 4 of class test.
#include<iostream.h>
#include<string.h>
class Retail {
char Category[20];
char Item[20]
int Qty;
float price;
Retail() {
strcpy(Category,”Cereal”);
strcpy(Item,”Rice”);
4
Qty=100;
Price=25;
`` }
public:
void show()
{
cout<<Category<<Item<<”:”<<Qty<<”@”<<price<<endl;
}
};
void main() {
Retail R;
R.show();
(i) Will statement 1 initialize all the data members for object R with the values given in the
function 1?(Yes or No). justify your answer suggesting the correction to be made in the
above code.
(ii) What shall be the possible output when the program gets executed ?
class Exam {
int Rno, MaxMarks, MinMarks ,Marks;
public:
Exam()
{
Rno=101;MaxMarks=100;MinMarks=40;Marks=75;
}
Exam(int prno, int pmarks)
{
Rno=prno; MaxMarks=100; MinMarks=40;score=pmarks;
}
~Exam()
{
5
cout<<”Exam Over”<<endl;
}
void show()
{
cout<<Rno<<”:”<< MaxMarks<<”:”<< MinMarks<<endl;
cout<<”[Marks Got]”<<Marks<<endl;
};
(i) As per Object oriented programming, which concept is illustrated by module 1 and
module2 together?
(ii) What is module 3 specifically reffered as? When do you think module3 will be
invoked/called?
a = I;
b = j;
c = k;
x=y=0;
void display() {
cout<<a<<b<<c<<x<<y<<endl;
};
6
8. Rewrite the following C++ program code after removing the
syntax error. Underline each correction.
#include<iostream.h>
class TRAIN {
long TrainNo;
char Description[25];
public:
void Entry() {
cin>>TrainNo; gets(Description);
}
void Display() {
cout<<TrainNo<<”:”<<Description<<endl;
}
};
void main() {
TRAIN T;
Entry.T(); Display.T();
#include<iostream.h>
class Client {
public:
void Enter();
void Modify();
7
Long returnCno() { return Cno;}
};
void ChangeEmail() {
Client C;
Fstream F;
F.open(“INFO.DAT”,ios::binary|ios::in|ios::out);
Long Cnoc;
cin>>Cnoc;
while(F.read((char*)&C, sizeof(C)) {
If(Cnoc == C.ReturnCno()) {
C.Modify();
int pos=_______
____________________
F.write((char*)&C, sizeof(C)));
F.close();
#include<iostream.h>
8
class ITEM {
public:
void ModifyPrice();
};
Fstream File;
File.open(“ITEM.DAT”,ios::binary|ios::in|ios::out);
int cino;
while(File.read((char*)this, sizeof(ITEM))) {
If(cino ==Ino) {
int FilePos=_______;
____________________;
File.write((char*)this, sizeof(ITEM)));
File.close();
9
10