Craete a class cylinder with radius and height as data member and perform the addition of two cylinders using constructor overloading.
#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;
}
Comments
Leave a comment