Answer to Question #248115 in C++ for jack

Question #248115

(Multilevel Inheritance):-

Derive a class named as BOX from RECTANGLE class. Take necessary

data & member functions for this box class to calculate the volume of the

box. All the data members are initialized through the constructors. Show the

result by accessing the area method of circle and rectangle and the volume

method of box class through the objects of box class.


1
Expert's answer
2021-10-07T23:38:37-0400

Source code


#include <iostream>


using namespace std;
class CIRCLE{
    private:
        double radius;
    public:
        CIRCLE(double rad){
            radius=rad;
        }
        void Area_circle(){
            double area=3.142*radius*radius;
            cout<<"\nArea of the circle: "<<area;
        }
};
class RECTANGLE: public CIRCLE{
    private:
        double length;
        double width;
    public:
        RECTANGLE(double l,double w): CIRCLE(l){
            length=l;
            width=w;
        }
        void Area_rect(){
            double area=length*width;
            cout<<"\nArea of the rectangle: "<<area;
        }
        
    
};
class BOX: public RECTANGLE{
    private:
        double length;
        double width;
        double height;
    public:
        BOX(double l, double w, double h):RECTANGLE(l,w){
            length=l;
            width=w;
            height=h;
        }
        void box_volume(){
            double volume=length*width*height;
            cout<<"\nVolume of the box: "<<volume;
        }
    
};


int main()
{
    BOX b(7,5,6);
    b.Area_circle();
    b.Area_rect();
    b.box_volume();


    return 0;
}

Sample Output




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS