See the UML class diagram of circle cylinder and implement inheritance relationship of classes in C++.

 See the UML class diagram of circle&cylinder and implement the inheritance relationship of classes in C++.

See the UML class diagram of circle&cylinder and implement the inheritance relationship of classes in C++.


Solution

#include<iostream>

using namespace std;

class Circle

{

protected:

double radius;

public:

Circle()

{

radius=0;

}

Circle(double r)

{

radius=r;

}

void set_radius()

{

cout<<endl;

cout<<"\tEnter Radius\t\t\t= ";

cin>>radius;

}

void get_radius()

{

cout<<"\tRadius is\t\t\t= "<<radius<<endl;

}

void GetArea()

{

double area;

area=3.14*radius*radius;

cout<<"\tArea is\t\t\t\t= "<<area<<endl;

cout<<"........................................."<<endl;

}

};

class Cylinder:public Circle

{

private:

double height;

public:

Cylinder()

{

height=0;

radius = 0;

}

Cylinder(double h, double rad)

{

height=h;

radius = rad;

}

void set_height()

{

cout<<endl;

cout<<"\tEnter Cylinder Height\t\t= ";

cin>>height;

}

void get_height()

{

cout<<"\tCylinder Height Is\t\t= "<<height<<endl;

}

void GetVolume()

{

double volume;

volume=3.14*radius*radius*height;

cout<<"\tCylinder Volume Is\t\t= "<<volume<<endl;

}

};

int main()

{

Circle r1;

cout<<"........................................."<<endl;

cout<<"                 For Circle        "<<endl;

cout<<"........................................."<<endl;

r1.set_radius();

r1.get_radius();

r1.GetArea();

Cylinder r2;

cout<<"........................................."<<endl;

cout<<"                 For Cylinder       "<<endl;

cout<<"........................................."<<endl;

r2.set_height();

r2.set_radius();

r2.get_height();

r2.get_radius();

r2.GetVolume();

return 0;

}


Output

See the UML class diagram of circle cylinder and implement inheritance relationship of classes in C++.
See the UML class diagram of circle cylinder and implement inheritance relationship of classes in C++. 





 random/hot-posts 

PROGRAMMING QUESTIONS/feat-big

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.