Question: Write a program that calculates the volume and total surface area of a cube or cuboid. The program should ask the user to input the dimensions of the shape and should check if the shape is a cube or a cuboid. If the shape is a cube, the program should display the volume and total surface area of the cube. If the shape is a cuboid, the program should display the volume and total surface area of the cuboid.

Question: Write a program that calculates the volume and total surface area of a cube or cuboid. The program should ask the user to input the dimensions of the shape and should check if the shape is a cube or a cuboid. If the shape is a cube, the program should display the volume and total surface area of the cube. If the shape is a cuboid, the program should display the volume and total surface area of the cuboid.

solution: -

#include<iostream>
using namespace std;c
class calculte{
int l,b,h;
int choice;
int area;
int volume;
public :
void cal(int x,int y,int z)
{
l=x;
b=y;
h=z;
if(l==b && b==h )
{
cout<<"All side are same "<<endl;
choice=1;
area_calculte();
}
else
{
cout<<"All side are not same "<<endl;
choice=2;
area_calculte();
}
}
void area_calculte()
{
switch(choice)
{
case 1:
volume=l*b*h;
cout<<"volume of the cube"<<" "<<volume;
area=6*(l*l);
cout<<"Total surface area of cube"<<" "<<area;
break;
case 2:
volume=l*b*h;
cout<<"Volume of the cuboid is "<<" "<<volume<<endl;
area=2*((l*b)+(b*h)+(h*l));
cout<<"Total surface area of the cubodial"<<area;
break;
}
}
};
int main()
{
int l,b,h;
cout<<"Enter the side "<<endl;
cin>>l>>b>>h;
// create object
calculte s1;
s1.cal(l,b,h);
return 0;
}

Comments