设计Person类 代码参考
程序员文章站
2022-03-25 17:16:33
1 #include 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 ......
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 }