Q.Write a menu driven program to calculate the TSA and volume of a
cube,cuboid and cylinder depending upon user's choice.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char ch[20];
float vol,area;
cout<<"Enter the desired shape:(D....)";
cin>>ch;
if(strcmp(ch,"Cube")==0)
{
int l;
cout<<"Enter length of the cube:";
cin>>l;
vol=l*l*l;
cout<<"The volume is:"<<vol;
area=6*l*l;
cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cuboid")==0)
{
int l,b,h;
cout<<"Enter length,breadth and height of the cube:";
cin>>l>>b>>h;
vol=l*b*h;
cout<<"The volume is:"<<vol;
area=2*(l*b+b*h+h*l);
cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cylinder")==0)
{
int r,d;
cout<<"Enter height and radius of the cylinder:";
cin>>d>>r;
vol=3.14*r*r*d;
cout<<"The volume is:"<<vol;
area=2*3.14*r*r+3.14*r*r*d;
cout<<"The surface area is:"<<area;
}
else
{
cout<<"Invalid choice";
}
getch();
}
cube,cuboid and cylinder depending upon user's choice.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char ch[20];
float vol,area;
cout<<"Enter the desired shape:(D....)";
cin>>ch;
if(strcmp(ch,"Cube")==0)
{
int l;
cout<<"Enter length of the cube:";
cin>>l;
vol=l*l*l;
cout<<"The volume is:"<<vol;
area=6*l*l;
cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cuboid")==0)
{
int l,b,h;
cout<<"Enter length,breadth and height of the cube:";
cin>>l>>b>>h;
vol=l*b*h;
cout<<"The volume is:"<<vol;
area=2*(l*b+b*h+h*l);
cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cylinder")==0)
{
int r,d;
cout<<"Enter height and radius of the cylinder:";
cin>>d>>r;
vol=3.14*r*r*d;
cout<<"The volume is:"<<vol;
area=2*3.14*r*r+3.14*r*r*d;
cout<<"The surface area is:"<<area;
}
else
{
cout<<"Invalid choice";
}
getch();
}
No comments:
Post a Comment