Answer to Question #193414 in C++ for VASANTH V

Question #193414

Develop a C++ program to calculate the area of a cube and compare the size of cube is larger using this pointer.


1
Expert's answer
2021-05-16T12:23:20-0400
#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:


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