You are on page 1of 10

1.

What Will be the output of the following program code:

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;
}

2. Given the following declaration identify the errors:

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);
};

3.Identify the error (s) in the following program code:

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;

4. Answer the questions (i)and(ii)after going through the


following class:

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;
}

};

(i)Which feature of Object oriented programming is demonstrated using function 1,


function 2,function 3 and function 4 in the above lass Test?

(ii) write statements in c++ that would execute function 4 of class test.

5. Answer the Quwtions (i)and (ii) after going through the


following class:

#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 ?

6. Answer the questions(i) and (ii)after going through the


following class:

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?

7. Identify the errors in the following program segment:


class x{

Static int a,b,c;

void read(int I, int j, char k) {

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();

9.Observe the program segment given below carefully and fill


the blanks marked as statement 1 and statement 2 using tellg() and
seekp() function for performing the required task.

#include<iostream.h>

class Client {

long Cno; char Name[20], Email[30];

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();

10. Observe the program segment given below carefully and


fill the blanks marked as statement 1 and statement 2 using
seekg(),seekp(),tellp() and tellg() function performing the
required task.

#include<iostream.h>

8
class ITEM {

int Ino; char Iname[20]; float price;

public:

void ModifyPrice();

};

void ITEM :: ModifyPrice() {

Fstream File;

File.open(“ITEM.DAT”,ios::binary|ios::in|ios::out);

int cino;

cout<<”Item no to Modify price:”;cin>>cino;

while(File.read((char*)this, sizeof(ITEM))) {

If(cino ==Ino) {

cout<<”present price:”<<price <<endl;

cout<<”changed price :”; cin>>price;

int FilePos=_______;

____________________;

File.write((char*)this, sizeof(ITEM)));

File.close();

9
10

You might also like