Develop a C++ program to calculate the area of a cube and compare the size of cube is larger using this pointer.
#include<bits/stdc++.h>
using namespace std;
class CubeArea
{
public:
double sideLength;
double area;
void areaCalculation();
};
void CubeArea::areaCalculation()
{
this->area=6*(this->sideLength)*(this->sideLength);
}
int main()
{
CubeArea x,y;
cout<<"Enter the side length of the cube 1: ";
cin>>x.sideLength;
cout<<"Enter the side length of the cube 2: ";
cin>>y.sideLength;
x.areaCalculation();
y.areaCalculation();
cout<<"Area of the cube 1: "<<x.area<<endl;
cout<<"Area of the cube 2: "<<y.area<<endl;
if(x.area>y.area)
cout<<"area of cube 1 is greater than area of cube 2"<<endl;
else if(x.area==y.area)
cout<<"area of cube 1 is equal to area of cube 2"<<endl;
else
cout<<"area of cube 2 is greater than area of cube 1"<<endl;
return 0;
}
Output:
Comments
Leave a comment