用c++求不同对象的面积

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:55:44
写一个c++程序,用函数承载求得不同对象(三角形,长方形,圆形)的面积,急等。

#include<iostream>
#include<cmath>
using namespace std;

#define PI 3.1415926f
float area(float );
float area(float ,float,int);
float area(float ,float ,float );

int main()
{
float a=3,b=5;
cout<<"三角形:"<<area(a,b,3)<<endl;
cout<<"长方形:"<<area(a,b,4)<<endl;
cout<<"圆:"<<area(a)<<endl;
cout<<"梯形:"<<area(a,b,a)<<endl;
return 0;
}
float area(float width,float height,int side)
{
if(side==4)
return width*height;
return width*height/2;
}

float area(float radius)
{
return PI*pow(radius,2);
}

float area(float upside,float downside,float height)
{
return (upside+downside)*height/2;
}

double calcu(double a,double b,double c)//三角形3边
double calcu(double a,double b)//长方形
double calcu