Friday 4 July 2014

51)write a program to evaluate,depending upon the choice of the user,the area of either a circle,a rectangle or a triangle

#include<iostream>
#include<cmath>
#include<cstdlib>
# define PI 3.14
using namespace std;
void menu();
void area_circle();
void area_rectangle();
void area_triangle();
int option;
float AREA;
int main()
{
  //int option;

  menu();
  switch (option)
     {
        case 1:
            area_circle();
            break;
        case 2:
            area_rectangle();
            break;
         case 3:
            area_triangle();
            break;
     }
    cout<<"area is" <<endl<<AREA;
}
void menu()
{
//float a,b,c, AREA;
  cout<<"1 :circle"<<endl;
  cout<<"2 :rectangle"<<endl;
  cout<<"3 :triangle"<<endl;
  cout<<"your option"<<endl;
  cin>>option;
  //cout<<"the area is "<<AREA;
 
}
void area_circle()
{
int R;//,AREA;
cout<<"enter the radius";
cin>>R;
AREA=PI*R*R;
}
void area_rectangle()
{
float a,b;//,AREA;
cout<<"enter the width and height"<<endl;
cin>>a>>b;
AREA=a*b;
}

void area_triangle()
{
float s,a,b,c;//,AREA;
cout<<"enter the side of the triagle"<<endl;
cin>>a>>b>>c;
s=(a+b+c)/2.0;
AREA=s*(s-a)*(s-b)*(s-c);
AREA=sqrt(AREA);
}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...