Q5: Consider the following code. [14] class A { protected: double x; public: A() { cout<<"Constructor of Class A"<Show(); Line 6: Ptr[1]->Display(); Line 7: Ptr[1]->Print(); Line 8: Ptr[2]=new D; Line 9: Ptr[2]->Show(); } a) List down the abstract and concrete classes? b) Find and correct the errors in the above code? c) Assume that all errors in the above code have been fixed. Now write the output of this program?
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Q5: Consider the following code. [14]
class A
{
protected:
double x;
public:
A()
{ cout<<"Constructor of Class A"<<endl; }
void Display(){cout<<"Function Display of Class A"<<endl;}
virtual void Print(){cout<<"Function Print of Class A";}
virtual void Show()=0;
};
class B:public A
{
protected:
double y;
public:
B(){cout<<"Constructor of Class B"<<endl;}
void Display(){cout<<"Function Display of Class B"<<endl;}
void Show(){cout<<"Function Show of Class B"<<endl;}
};
class C:public A
{
public:
C(){cout<<"Constructor of Class C"<<endl;}
void Display(){cout<<"Function Display of Class C"<<endl;}
};
class D:public B
{};
void main()
{
Line 1: A *Ptr[3];
Line 2: P[0]=new A;
Line 3: Ptr[1]=new B;
Line 4: Ptr[2]=new C;
Line 5: Ptr[1]->Show();
Line 6: Ptr[1]->Display();
Line 7: Ptr[1]->Print();
Line 8: Ptr[2]=new D;
Line 9: Ptr[2]->Show();
}
a) List down the abstract and concrete classes?
b) Find and correct the errors in the above code?
c) Assume that all errors in the above code have been fixed. Now write the output of this program?
d) Draw virtual function table(s) for classes given in the above code segment?
Step by step
Solved in 3 steps