Answer to Question #247968 in C++ for Kumar

Question #247968

Modify the program no. 1 as follows:


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-07T03:04:23-0400
#include<iostream>
#include<cmath>
using namespace std;
class  CIRCLE{
	private:
		double rad;
	public:
		CIRCLE(){
			
		}
		 CIRCLE(double r){
			rad = r;
		}
		void setData(double r){
			rad = r;
		}
	
		double area(){
		
		return 3.142 * pow(rad, 2);
		
		}
		
		
};


class CYLINDER: CIRCLE{
	private:
	double	height;
	public:
		CYLINDER(double rad,  double h){
			setData(rad);
			height = h;
		}
		
		void volume(){
		
		
			cout<<"Volume is: "<<area() * height<<endl;
		}
	
};


int main(){
	


CYLINDER cy(7, 10);
cy.volume();
	
}

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