In: Computer Science
Class object in C++ programming language description about lesson inheritance multi level example.
#include
#include
using namespace std;
class B{
protected:
int x;
public:
B(int xx=1):x(xx){}
void setx(int xx){
x=xx;
}
int getx(){
return x;
}
};
class C:public B{
protected:
int y;
public:
C(int xx=1,int yy=2):B(xx),y(yy){}
void setx(int yy){
y=yy;
}
int gety()const{
return y;
}
};
class D:public C{
private:
int z;
int getvalue(string message){
int v;
while(cin.fail()){
cout<<"---Invalid----"<
cin.ignore(100,'\n');
}return v;
}
public:
D(int xx=1, int yy=2, int zz=3)
:C(xx,yy),z(zz){
}
void getz()const{
return z;
}
void input(){
x=getvalue("Enter x= ");
y=getvalue("Enter y= ");
z=getvalue("Enter z= ");
}
void print(){
cout<
}
int Max(){
int m=x;
m=(m
return(m
}
void change(int &a, int &b){
int t=a;
a=b;
b=t;
}
void sort(){
if(x>y)change(x,y);
if(y>z)change(y,z);
if(x>y)change(x,y);
}
int product(){
return x*y*z;
}
};
void head(){
cout<
cout<
}
int main(){
D dd(10,20,30);
cout<<"x= "<
cout<<"y= "<
cout<
head();
dd.input();
head();
dd.print();
}