Answer to Question #244166 in C++ for Smiley

Question #244166

Craete a class cylinder with radius and height as data member and perform the addition of two cylinders using constructor overloading.


1
Expert's answer
2021-09-29T18:48:28-0400
#include<iostream>
using namespace std;
class Cylinder{
	private:
		float radius, height;
	public:
		Cylinder( ){
			
		}
		
		Cylinder(float r, float h){
			radius = r;
			height = h;
		}
		
	friend Cylinder add(Cylinder c1, Cylinder c2 );
		
		void display(){
			cout<<"Radius:  "<<radius<<"\nHeight:   "<<height<<endl;
		}
};
	Cylinder add(Cylinder c1, Cylinder c2 ){
			Cylinder lind;
			 lind.radius = c1.radius + c2.radius;
			 lind.height = c1.radius + c2.radius;
			 
			return lind;
		}
int main(){
	Cylinder c1(9,10), c2(12,11), c3;
	c3 = add(c1, c2);
	c3.display();
	
	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