Answer to Question #248116 in C++ for john

Question #248116

(Hierarchical Inheritance):-

Derive a class named as CYLINDER from CIRCLE class. Take necessary

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

cylinder. Show the result by accessing the area method of circle and

rectangle through object of rectangle class and the area of circle and volume

method of cylinder class through the objects of cylinder class.


1
Expert's answer
2021-10-08T00:32:39-0400
#include<iostream>
using namespace std;
class Circle    
{
    protected:
            float r ;          
    public:
    void E(void)
    {
        cout <<"Enter the radius: "; 
		cin >>r;
    }
    void Dis(void)
    {
        cout <<"The area = " << (22/7 * r*r);
    }
};


class Rectangle 
{
    protected:
            float x, y ;
    public:
    void E_l(void)
    {
	    cout << "\nEnter the length : "; 
		cin >>x;
	    cout << "Enter the breadth : " ; 
		cin >>y;
    }
    void Display(void)
    {
        cout <<"The area = "<<(x * y);
    }
};




class Cylinder : public Circle, public Rectangle 
    {
	public:
	void volume(void)
	{
	    cout <<"\nThe volume of the cylinder is: "
	            << (22/7* r*r*x) ;
	}
};




int main()
{
    Circle c ;
    cout <<"\nCircle dimensions\n" ;
    c.E( );
    c.Dis( );
    Rectangle r ;
    cout << "\n\nRectangle dimensions";
    r.E_l( );
    r.Display( );
    Cylinder m ; 
    cout <<"\n\nCylinder dimensions\n";
    m.E( );
    m.E_l( );
    m.volume( );
return 0;
}

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