Multilevel Inheritance in C++

Find the area of circle and rectangle using multilevel inheritance

5 comments:

  1. #include
    using namespace std;
    class value
    {
    public:
    int w,h,r;
    float c,R;
    void get_v()
    {
    cout<<"Enter value of height and width :"<>w>>h;
    cout<<"Enter value of R :"<>r;
    a=w;
    b=h;
    d=r;
    }
    protected:
    int a,b,d;
    };
    class circle: public value
    {
    public:
    void a_c(){
    c=(0.5*3.1416*(d*d));
    cout<<"Area of ciecle is :"<<c<<endl;
    }
    };
    class rect:public circle
    {
    public:
    void a_r()
    {
    R=(a*b);
    cout<<"Area of Rectangle is :"<<R<<endl;
    }
    };
    int main()
    {
    rect obj;
    obj.get_v();
    obj.a_c();
    obj.a_r();
    }

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. #include
    using namespace std;
    class B
    {
    public:
    void get_values();

    };
    void B::get_values()
    {
    cout<<"Circle area is:"<>r;
    a=(0.5*3.14*r*r);
    cout<>hight>>wide;
    cout<<"Your Rectangle is:"<<endl;
    cout<<hight*wide<<endl;
    }
    int main()
    {
    D d;
    d.get_values();
    d.get_value();
    d.set_values();
    d.display();
    }

    ReplyDelete
  4. //p1
    #include
    using namespace std;
    class B
    {
    public:
    void get_values();

    };
    void B::get_values()
    {
    cout<<"Circle area is:"<>r;
    a=(0.5*3.14*r*r);
    cout<<a<<endl;
    }

    void IB::set_values()
    {
    int w,h;
    hight=h;
    wide=w;
    }
    class D:public IB
    {
    public:
    void display();


    };

    ReplyDelete
  5. //p2
    void D::display()
    {
    cout<<"Enter your values:"<>hight>>wide;
    cout<<"Your Rectangle is:"<<endl;
    cout<<hight*wide<<endl;
    }
    int main()
    {
    D d;
    d.get_values();
    d.get_value();
    d.set_values();
    d.display();
    }

    ReplyDelete

Comment Here