0% found this document useful (0 votes)
8 views2 pages

U M

The document contains a C++ program that calculates the volumes of a cube, cylinder, and sphere using user input. It defines three functions to compute the respective volumes based on the given dimensions. The program then prompts the user for inputs and displays the calculated volumes for each shape.

Uploaded by

umarmirase
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

U M

The document contains a C++ program that calculates the volumes of a cube, cylinder, and sphere using user input. It defines three functions to compute the respective volumes based on the given dimensions. The program then prompts the user for inputs and displays the calculated volumes for each shape.

Uploaded by

umarmirase
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UMARFARUKH MIRASE

CLASS FY IT2
ROLL NO.24103043

VOLUME OF CUBE ,CYLINDER AND SPHERE:-


#include<iostream>
#include <cmath> //for M_PI(constant for Pi)

using namespace std;

//Function to calculate the volume of a cube


int volume(int side){
return pow(side,3);

}
//Function to calculate the volume of a cylinder
double volume(double radius,double height){
return M_PI*pow(radius,2)*height;
}

//Function to calculate the volume of a sphere


double volume(double radius){
return(4.0/3.0)*M_PI*pow(radius,3);
}

int main(){
double radius,height;
int side;

//Inpute for cube


cout<<"Enter the side length of the cube:";
cin>>side;
cout<<"Volume of the cube:"<<volume(side)<<endl;

//Inpute for cylinder


cout<<"Enter the radius and height of the cylinder:";
cin>>radius>>height;
cout<<"Volume of the cylinder:"<<volume(radius,height)<<endl;

//Inpute for sphere


cout<<"Enter the radius of the sphere:";
cin>>radius;
cout<<"Volume of the sphere:"<<volume(radius)<<endl;

return 0;
}

OUTPUT:-
sdl@sdl4:~$ g++ s.cpp
sdl@sdl4:~$ ./a.out
Enter the side length of the cube:15 6
Volume of the cube:3375
Enter the radius and height of the cylinder:10
Volume of the cylinder:1130.97
Enter the radius of the sphere:6
Volume of the sphere:904.779
sdl@sdl4:~$

You might also like