Volume Of Cube
When finding the volume of the cube, we should understand that all sides of a cube are of the same length and due to height, length and width of the cube are same, we use only one symbol in the formula to represent all the dimensions.
Volume of Cube Formula: volume = s3
where s represents the length of each side of a cube.
for example, suppose the length of the edge of a cube is 6cm then substitute the value in the volume of cube formula.
volume = s3
volume = 63
volume = 6*6*6 =216 cm3
therefore it would take 216 cubic units to fill the cube.
Volume Of Sphere
where r is the radius of a sphere and if you can also
find the radius by dividing the diameter by 2
Program to find Volume of Cube, Cylinder and Sphere
#include<cmath>
using namespace std;
class volume
{
double vol;
public:
void calculateVolume(int side)
{
vol = pow(side,3);
display();
}
void calculateVolume(double radius, double height)
{
vol = M_PI*pow(radius,2)*height;
display();
}
void calculateVolume(double radius)
{
vol = M_PI*pow(radius,3)*4/3;
display();
}
void display()
{
cout<<“Volume = “<<vol<<endl;
}};
int main()
{int s,h;
float r;
volume a;
cout<<“Cube – Enter the Side : “;
cin>>s;
a.calculateVolume(s);
cout<<“Cylinder – Enter the Radius and Height : “;
cin>>r>>h;
a.calculateVolume(r,h);
cout<<“Sphere – Enter the Radius : “;
cin>>r;
a.calculateVolume(r);
return 0;}
double vol;
public:
void calculateVolume(int side)
{
vol = pow(side,3);
display();
}
void calculateVolume(double radius, double height)
{
vol = M_PI*pow(radius,2)*height;
display();
}
void calculateVolume(double radius)
{
vol = M_PI*pow(radius,3)*4/3;
display();
}
void display()
{
cout<<“Volume = “<<vol<<endl;
}};
int main()
{int s,h;
float r;
volume a;
cout<<“Cube – Enter the Side : “;
cin>>s;
a.calculateVolume(s);
cout<<“Cylinder – Enter the Radius and Height : “;
cin>>r>>h;
a.calculateVolume(r,h);
cout<<“Sphere – Enter the Radius : “;
cin>>r;
a.calculateVolume(r);
return 0;}
OUTPUT:
Cube – Enter the Side : 5
Volume = 125
Cylinder – Enter the Radius and Height : 7 4
Volume = 615.752
Sphere – Enter the Radius : 7
Volume = 1436.76
You must be also searching for these programming languages :
Cube – Enter the Side : 5
Volume = 125
Cylinder – Enter the Radius and Height : 7 4
Volume = 615.752
Sphere – Enter the Radius : 7
Volume = 1436.76
You must be also searching for these programming languages :
tags: volume of sphere, volume of cube, volume of cylinder, volume of sphere formula, volume of cube formula