设计并测试Trapezium类 代码参考
1 #include <iostream> 2 3 using namespace std; 4 5 class Trapezium 6 { 7 private: 8 int x1,y1,x2,y2,x3,y3,x4,y4; 9 public: 10 void initial(){x1=0,x2=0;x3=0;x4=0;y1=0;y2=0;y3=0;y4=0;return;} 11 void GetPosition(int&,int&,int&,int&,int&,int&,int&,int&); 12 void Area() 13 { 14 double s; 15 s=((x2-x1)+(x4-x3))*(y2-y4)/2.0; 16 cout<<s<<endl; 17 return; 18 } 19 }; 20 21 void Trapezium::GetPosition(int& a,int& b,int& c,int& d,int& e,int& f,int& g,int& h) 22 { 23 x1=a;y1=b;x2=c;y2=d;x3=e;y3=f;x4=g;y4=h; 24 return; 25 } 26 27 int main() 28 { 29 int x[4],y[4]; 30 Trapezium one; 31 for(int i=0;i<4;i++) cin>>x[i]>>y[i]; 32 one.initial(); 33 one.GetPosition(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); 34 one.Area(); 35 return 0; 36 }