PROGRAM
Program to display a menu regarding rectangle opertion and perform according to user's response.#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
char ch,ch1;
float l,b,pm,area,diag;
do
{
clrscr();
cout<<"\n"<<"Rectangle Menu";
cout<<"\n1.Area";
cout<<"\n2.Perimeter";
cout<<"\n3.Diagonal";
cout<<"\n4.Exit"<<"\n";
cout<<"Enter your choice:";
cin>>ch;
if(ch=='1'||ch=='2'||ch=='3')
{
cout<<"\n"<<"Enter length & breadth :";
cin>>l>>b;
}
switch(ch)
{
case'1' : area=l*b;
cout<<"Area:"<<area<<endl;
break;
case'2' : pm=2*(l+b);
cout<<"Perimeter :"<<pm<<endl;
break;
case'3' : diag=sqrt(l*l+b*b);
cout<<"Diagonal :"<<diag<<endl;
break;
case'4' : break;
default : cout<<"Wrong choice!\n";
break;
}
cout<<"\nPress a key to continue...\n";
ch1=getchar();
} while(ch>='1'&&ch<='3');
getch();
return 0;
}
========================================================================
OUTPUT
Rectangle Menu
1.Area
2.Perimeter
3.Diagonal
4.Exit
Enter your choice:1
Enter length & breadth : 2 3
Area : 6
Press a key to continue...
========================================================================
No comments:
Post a Comment