#include<iostream.h> #include<math.h> #define pi 3.14 class cshape { int x,y; public: cshape(int x1,int y1) { x=x1; y=y1; } virtual float getarea(){return 0;}; }; class trial:public cshape { int i,j,k; public: trial(int i1,int j1,int k1,int x1,int y1):cshape(x1,y1) { i=i1; j=j1; k=k1; } float p; float getarea() { p=(float)(i+j+k)/2; return (float)sqrt(p*(p-i)*(p-j)*(p-k)); } }; class squrt:public cshape { int a; public: squrt(int a1,int x1,int y1):cshape(x1,y1) { a=a1; } float getarea() { return (float)a*a; } }; class circle:public cshape { int r; public: circle(int r1,int x1,int y1):cshape(x1,y1) { r=r1; } float getarea() { return (float)pi*r*r; } }; void getarea1(cshape &l) { cout<<l.getarea()<<endl; } void main() { int i1,j1,k1,a1,r1,m,x1=0,y1=0; cout<<"************(1)三角形****************"<<endl; cout<<"************(2)正方形****************"<<endl; cout<<"************(3)圆********************"<<endl; cout<<"请输入你要计算面积的图形的序号"<<endl; cin>>m; if(m==1) { cout<<"请输入三边的长度"<<endl; cin>>i1>>j1>>k1; int n; n=(i1+j1+k1)/2; if(n*(n-i1)*(n-j1)*(n-k1)<=0) cout<<"无法组成三角形"<<endl; else { trial tri(i1,j1,k1,x1,y1); getarea1(tri); } } else if(m==2) { cout<<"请输入正方形的边长"<<endl; cin>>a1; squrt squ(a1,x1,y1); getarea1(squ); } else { cout<<"请输入圆的半径"<<endl; cin>>r1; circle cir(r1,x1,y1); getarea1(cir); } }