//设计并测试一个名为Trapezium的梯形类,其属性为梯形的四个顶点的坐标。该梯形上边和下边均和x轴平行。
//根据类的封装性要求,在类的声明中用8个私有的整型变量表示4个点的坐标值,
//声明成员函数initial(int, int, int, int, int, int, int, int)初始化数据成员
//函数GetPosition(int&, int&, int&, int&, int&, int&, int&, int&)读取坐标值,函数Area()计算面积。
#include<iostream>
using namespace std;
class Trapezium
{
int x1, x2, x3, x4, y1, y2, y3, y4;
public:
void initial(int a1, int a2, int a3, int a4, int b1, int b2, int b3, int b4)
{
x1 = a1; x2 = a2; x3 = a3; x4 = a4; y1 = b1; y2 = b2; y3 = b3; y4 = b4;
}
void GetPosition(int& a1, int& a2, int& a3, int& a4, int& b1, int& b2, int& b3, int& b4)//为什么要引用
{
cout << a1 << " " << a2 << " " << a3 << " " << a4 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << endl;
}
double Area()//为什么不写形参进去
{
return (1 * (x2 - x1) + (x4 - x3)) * (y1 - y3) / 2;
}
};
void test01()
{
Trapezium t1;
int a, b, c, d, e, f, g, h;
cin >> a >> b >> c >> d >> e >> f >> g >> h;
t1.initial(a, b, c, d, e, f, g, h);
t1.GetPosition(a, b, c, d, e, f, g, h);
cout << t1.Area() << endl;
}
有两个问题