Question

In: Computer Science

Class object in C++ programming language description about lesson inheritance multi level example.

Class object in C++ programming language description about lesson inheritance multi level example.

Solutions

Expert Solution

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

}


Related Solutions

Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson unary overloading function example.
Class object in C++ programming language description about lesson unary overloading function example.
Code in C++ programming language description about chose favorite fruit and wage color of fruit in lesson Class object (Multiple class).
Code in C++ programming language description about chose favorite fruit and wage  color of fruit in lesson Class object (Multiple class).
Code in C++ programming language description about lesson Calculator (multiple, sum, dived, sub) example.
Code in C++ programming language description about lesson Calculator (multiple, sum, dived,  sub) example.
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT