|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
只有最后一个函数void display()是输出三角形的坐标,周长和面积。不知道怎么调用出了三个point的x, y来计算了 去高手解答!! 其他部分没有问题 编译通过了- - 我用了接近两个小时呀 汗
- #include <iostream>
- #define PI 3.14159
- using namespace std;
- class Point
- {
- public:
- Point(int xx = 0, int yy = 0) //(1)带参数的缺省构造函数。如:point(int xx=0,int yy=0);
- {
- x = xx;
- y = yy;
- }
- Point(Point &p);//(2)拷贝构造函数
- void set_value(int xx, int yy); //(3)设置x,y坐标值
- void get_value(int &xx, int &yy); //(4)取x,y坐标值,参数为两个整形量的引用,分别用于获取x,y的坐标值。
- private:
- int x;
- int y;
- };
- Point::Point(Point &p)
- {
- x = p.x;
- y = p.y;
- }
- void Point::set_value(int xx, int yy)
- {
- x = xx;
- y = yy;
- }
- void Point::get_value(int &xx, int &yy)
- {
- xx = x;
- yy = y;
- } //Point类结束
- class Triangle
- {
- public:
- Triangle(int x1 , int y1, int x2, int y2, int x3, int y3); //(1)带参数的缺省构造函数,参数为整型x1,y1,x2,y2,x3,y3,分别是三个顶点
- Triangle(Point &p1, Point &p2, Point &p3); //(2)带参数的构造函数,参数是三个point类对象的引用。
- void set_value1(int x1, int y1); //(3)设置顶点p1坐标,参数为两个整型参数。
- void set_value2(int x2, int y2); //(4)设置顶点p2坐标,参数为两个整型参数。
- void set_value3(Point &p); //(5)设置顶点p3坐标,参数是一个point类对象的引用。
- void pointer1(int *p1, int *p2); //(6)取顶点1坐标,参数为两个整型变量的指针,即将两个坐标值放入两个指针指向的变量中。
- void pointer2(int *p1, int *p2); //(7)取顶点2坐标,参数为两个整型变量的引用,即将两个坐标值赋值给个引用变量。
- void pointer3(Point &p); //(8)取顶点3坐标,参数是一个point类对象的引用。
- void display(); //(9)输出三角形的三个顶点的坐标、周长和面积。
- private:
- Point point1;
- Point point2;
- Point point3;
- };
- Triangle::Triangle(int x1=0, int y1=0, int x2=1, int y2=1, int x3=-1, int y3=-1)
- {
- point1.set_value(x1, y1);
- point2.set_value(x2, y2);
- point3.set_value(x3, y3);
- }
- Triangle::Triangle(Point &p1, Point &p2, Point &p3)
- {
- point1 = p1;
- point2 = p2;
- point3 = p3;
- }
- void Triangle::set_value1(int x1, int x2)
- {
- point1.set_value(x1, x2);
- }
- void Triangle::set_value2(int x2, int y2)
- {
- point2.set_value(x2, y2);
- }
- void Triangle::set_value3(Point &p)
- {
- point3 = p;
- }
- void Triangle::pointer1(int *p1, int *p2)
- {
- point1.get_value(*p1, *p2);
- }
- void Triangle::pointer2(int *p1, int *p2)
- {
- point2.get_value(*p1, *p2);
- }
- void Triangle::pointer3(Point &p)
- {
- p = point3;
- }
- void Triangle::display()
- {
- cout << "the point of the triangle is: " << endl;
- }
- int main()
- {
- return 0;
- }
复制代码
|
|