c ++ I did areas of these. I want to Use FUNCTIONS to find the areas of different geometrical figures. This has 4 options that can be chosen by the user. The 4 options are – a) Area of a circle b) Area of a rectangle c) Area of a triangle d) Area of a square
#include<iostream>
using namespace std;
int area(int);
int area(int ,int);
float area(float);
float area(float ,float);
int main()
{
int s ,l ,c;
float r ,b ,h;
cout <<"Enter radius of circle:";
cin >>r;
cout<<"Enter length and breadth of rectangle:";
cin>>l>>c;
cout<<"Enter base and height of triangle:";
cin>>b>>h;
cout<<"Enter side of a square:";
cin>>s;
cout<<endl;
cout<<"Area of circle: "<<area(r)<<endl;
cout<<"Area of rectangle: "<<area(l,c)<<endl;
cout<<"Area of triangle: "<<area(b,h)<<endl;
cout<<"Area of square: "<<area(s)<<endl;
}
int area(int s)
{
return(s*s);
}
int area(int l,int c)
{
return(l*c);
}
float area(float r)
{
return(3.14*r*r);
}
float area(float b,float h)
{
return((b*h)/2);
}
Aucun commentaire:
Enregistrer un commentaire