You are on page 1of 2

OOP-BIT Fall 2017

Name: ________________ Quiz 4 (ID: 1) Roll No: ________________


Q1. Write output of the code in front of each function call. If any line has syntax or logical error, underline it and give
reason below the box: [In any case, write output of lines without error]
class A{ B *ptrB=new B;
public: ptrB->f1();
void f1(){cout<<"F1 A\n";}
ptrB->f2();
virtual void f2(){cout<<"F2
A\n";} ptrB->f4();
void f4(){cout<<"F4 A\n";} A *ptrA=ptrB;
}; ptrA->f1();
class B:public A{ ptrA->f2();
public:
virtual void f1(){cout<<"F1 ptrA->f3();
B\n";} ptrA=new C;
void f2(){cout<<"F2 B\n";} ptrA->f1();
void f3(){cout<<"F3 B\n";} ptrA->f2();
};
ptrA->f3();
class C:public B{
public: C *ptrC=ptrB;
void f1(){cout<<"F1 C\n";} ptrC->f1();
void f2(){cout<<"F2 C\n";} ptrC->f2();
void f3(){cout<<"F3 C\n";}
ptrC->f3();
void f4(){cout<<"F4 C\n";}
};
Write errors here:
__________________________________________________________________________________________________

__________________________________________________________________________________________________

__________________________________________________________________________________________________

Q2. Write output of the code in front of each function call. If any line has error, underline it and give reason below the
box:
class A{ class D:virtual public B, virtual public C{
public: public:
A(){cout<<"A ";} D(){cout<<"D ";}
~A(){cout<<"DA ";} ~D(){cout<<"DD ";}
void f1(){ cout<<"F1 A "; } };
};
D *ptrD=new D;
class B:public A{
public: ptrD->f1();
B(){cout<<"B ";} B *ptrB=ptrD;
~B(){cout<<"DB ";} delete ptrB;
};
class C:public A{
public:
C(){cout<<"C ";}
~C(){cout<<"DC ";}
};
Write errors here:
__________________________________________________________________________________________________

__________________________________________________________________________________________________
Punjab University College of Information Technology Resource Person: Abdul Mateen
OOP-BIT Fall 2017
Q3. Write all classes used in first column. Add required member functions in classes, according to code+common sense?
Printer *p=new SimplexP; Printer
p-print(); I am Simplex Printer
p=new DuplexP;
p->print(); I am Parent Printer SimplexP DuplexP
delete p; I am destructor of Duplex
p=new ColorSP;
p->print(); I am Simplex Color Printer ColorSP
ColorSP *cp=(ColorSP*)p;
cp->colorPrinting(); I can do color printing

Punjab University College of Information Technology Resource Person: Abdul Mateen

You might also like