//base class A
//class B derived from class A
//class C derived from class B
//with parameterized constructor to initialize data members
#include <iostream>
using namespace std;
class A
{
protected:
int a;
public:
A()
{
a=0;
}
A(int x) //parameterized constructor
{
a=x;
}
DisplayA()
{
cout<<"a="<<a<<endl;
}
};
class B:public A
{
protected:
int b;
public:
B()
{
b=0;
}
B(int x,int y):A(x) //parameterized constructor
{
b=y;
}
DisplayB()
{
cout<<"b="<<b<<endl;
}
};
class C:public B
{
protected:
int c;
public:
C()
{
c=0;
}
C(int x,int y,int z):B(x,y) //parameterized constructor
{
c=z;
}
DisplayC()
{
cout<<"c="<<c<<endl;
}
};
int main()
{
C objectC(1,2,3);
objectC.DisplayA();
objectC.DisplayB();
objectC.DisplayC();
return 0;
}
{
protected:
int a;
public:
A()
{
a=0;
}
A(int x) //parameterized constructor
{
a=x;
}
DisplayA()
{
cout<<"a="<<a<<endl;
}
};
class B:public A
{
protected:
int b;
public:
B()
{
b=0;
}
B(int x,int y):A(x) //parameterized constructor
{
b=y;
}
DisplayB()
{
cout<<"b="<<b<<endl;
}
};
class C:public B
{
protected:
int c;
public:
C()
{
c=0;
}
C(int x,int y,int z):B(x,y) //parameterized constructor
{
c=z;
}
DisplayC()
{
cout<<"c="<<c<<endl;
}
};
int main()
{
C objectC(1,2,3);
objectC.DisplayA();
objectC.DisplayB();
objectC.DisplayC();
return 0;
}
No comments:
Post a Comment