#include<iostream.h> #include<math.h> class tria; class cpoint { int x1,y1,x2,y2,x3,y3; public: cpoint(int a1,int b1,int a2,int b2,int a3,int b3) { x1=a1; y1=b1; x2=a2; y2=b2; x3=a3; y3=b3; } void change(tria &); }; class tria { double d1,d2,d3,p; public: tria(int a1,int b1,int a2,int b2,int a3,int b3 ) { d1=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)); d2=sqrt((a1-a3)*(a1-a3)+(b1-b3)*(b1-b3)); d3=sqrt((a2-a3)*(a2-a3)+(b2-b3)*(b2-b3)); p=(d1+d2+d3)/2; } double mianji() { return sqrt(p*(p-d1)*(p-d2)*(p-d3)); } friend void cpoint::change(tria &); }; void cpoint::change(tria &c) { cout<<"这个三角形面积为"<<c.mianji()<<endl; } void main() { int a1,b1,a2,b2,a3,b3; for(int i=0;;i++) { cout<<"请输入一个点的信息"<<endl; cin>>a1>>b1; cout<<"请输入第二个点的信息"<<endl; cin>>a2>>b2; cout<<"请输入第三个点的信息"<<endl; cin>>a3>>b3; cpoint cp(a1,b1,a2,b2,a3,b3); tria c(a1,b1,a2,b2,a3,b3); cp.change(c); int j; cout<<"如果要继续输入请按1否则按0"<<endl; cin>>j; if(j) continue; else break; } }