Tuesday, October 18, 2011

C ++ Program To Find Area Of Rectangle Circle Triangle Pyramid Using Choice



Aim 
To write  a c plus plus program to find area of rectangle,circle,triangle and pyramid by using menu and choice.
Program 
#include<iostream>
#include<math.h>
using namespace std;
main()
{
 int area(int,int);
 float area(float,float,float);
 float area(float);
 double area(float,int);
int n;
cout<<"Menu\n";
cout<<"1.Rectangle\n";
cout<<"2.Circle\n";
cout<<"3.Triangle\n";
cout<<"4.Pyramid\n";
cout<<"Enter your choice\n";
cin>>n;
int l,br,p;
float a,b,c,r,d;
float m;
switch(n)
{
case 1: {
cout<<"Enter the length and breadth of a rectangle\n";
cin>>l>>br;
cout<<"The area of regtangle is "<<area(l,br)<<"\n";
break;
       }
case 2: {
cout<<"Enter the radius of a circle\n";
cin>>r;
cout<<"The area of circle is "<<area(r)<<"\n";
break;
}
case 3: {
cout<<"Enter the side of triangle\n";
cin>>a>>b>>c;
cout<<"The area of triangle is\n";
          d=area(a,b,c);
         cout<<d;
break;
}
case 4:{
cout<<"Enter the base and height of a pyramid\n";
cin>>m>>p;
cout<<"The area of a pyramid"<<area(m,p);
break;
}
}
return 0;
}
int area(int l,int br)
{
 return(l*br);

float area(float r)
{
return(3.14*r*r);
}
float area(float a,float b,float c)


{ float s,d;
 s=(a+b+c)/2.0;
d=sqrt(s*(s-a)*(s-b)*(s-c));
 return(d);
}
double area(float m,int p)
{
return((m*m)+(2*m*p));
}



Tags : c++ program to find area of rectangle , c++ program to find area of circle , c++ program to find area of triangle , c++ program to find area of pyramid , c++ program to find area using functions , algorithm to find area of triangle , circle , rectangle ,pyramid 

No comments:

Post a Comment