蓝山帝景
#include <iostream>#include <math.h>#define PI 3.14using namespace std;class Shape //Shape这个类里面重载了计算面积的函数{public:float Shape::GetArea(float radious)//计算圆的面积{return float (PI*radious*radious);}float Shape::GetArea(float side1, float side2, float side3)//计算三角形面积{float average=(side1+side2+side3)/2;return float (sqrt(average * (average-side1) * (average-side2) * (average-side3)));}float Shape::GetArea(float side1, float side2)//计算长方形面积{return float (side1 * side2);}};class Triangle : public Shape{public:float side1, side2 ,side3;public:Triangle(){cout<<"输入三角形三边长度:"<<endl;cin>>side1>>side2>>side3;}};class Circle : public Shape{public:float radious;public:Circle(){cout<< "输入圆的半径:"<<endl;cin>>radious;}};class Rectangle : public Shape{public:float side1, side2;public:Rectangle(){cout<<"输入长方形的长和宽:"<<endl;cin>>side1>>side2;}};int main(){int num;cout<<"请选择你要计算面积的图形:"<<endl<<"1.三角形 2.圆形 3.矩形"<<endl;do{cin>>num;switch(num){case 1:{Triangle* T = new Triangle;cout<<"三角形的面积为:"<<T->GetArea(T->side1, T->side2, T->side3)<<endl;delete T;break;}case 2:{Circle* C = new Circle;cout<<"圆的面积为:"<<C->GetArea(C->radious)<<endl;delete C;break;}case 3:{Rectangle* R = new Rectangle;cout<<"长方形的面积为:"<<R->GetArea(R->side1, R->side2)<<endl;delete R;break;}default:cout<<"请在1-3之间选择:";}}while (num != 1|| num != 2|| num != 3);return 0;}