Program:- Find the volume of cylinder, cube and rectangular box.
Coding:-
#include<iostream.h>
float volume(float r, float h)
{
float vol;
vol= 3.14*(r*r)*h;
return vol;
}
float volume(float s)
{
float vol;
vol=s*s*s;
return vol;
}
float volume (float l, float b, float h)
{
float vol;
vol=l*b*h;
return vol;
}
void main()
{
float radius, side , length, breadth, height , vol;
int option;
do{
cout<<" \n enter 1 for cylinder, 2 for cube, 3 for rectangular box and 4 for exit ";
cin>>option;
switch(option)
{
case 1 : cout<<"enter the value of radius and height of cylinder\n";
cin>>radius>>height;
vol=volume(radius, height);
cout<< "volume = "<<vol<<" cubic units \n";
break;
case 2: cout<<"enter the value of side \n";
cin>>side;
vol=volume (side);
cout<<"\n volume = "<<vol<<" cubic unit";
break;
case 3: cout<<" enter the value of length, breadth and height ";
cin>>length>>breadth>>height;
vol=volume(length,breadth,height);
cout<<"\n volume = "<<vol<<" cubic unit";
break;
default: cout<<"invalid entry ";
break;
}
} while (option>0 && option< 4);
}
Output:-
Coding:-
#include<iostream.h>
float volume(float r, float h)
{
float vol;
vol= 3.14*(r*r)*h;
return vol;
}
float volume(float s)
{
float vol;
vol=s*s*s;
return vol;
}
float volume (float l, float b, float h)
{
float vol;
vol=l*b*h;
return vol;
}
void main()
{
float radius, side , length, breadth, height , vol;
int option;
do{
cout<<" \n enter 1 for cylinder, 2 for cube, 3 for rectangular box and 4 for exit ";
cin>>option;
switch(option)
{
case 1 : cout<<"enter the value of radius and height of cylinder\n";
cin>>radius>>height;
vol=volume(radius, height);
cout<< "volume = "<<vol<<" cubic units \n";
break;
case 2: cout<<"enter the value of side \n";
cin>>side;
vol=volume (side);
cout<<"\n volume = "<<vol<<" cubic unit";
break;
case 3: cout<<" enter the value of length, breadth and height ";
cin>>length>>breadth>>height;
vol=volume(length,breadth,height);
cout<<"\n volume = "<<vol<<" cubic unit";
break;
default: cout<<"invalid entry ";
break;
}
} while (option>0 && option< 4);
}
Output:-
No comments:
Post a Comment