Description

在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。

Input

输入的第一行为N,表示后面有N行测试样例。每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。

Output

输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
C语言的输入输出被禁用。

Sample Input

4 0,0 1,1 1,1 2,3 2,3 4,5 0,1 1,0

Sample Output

Point : (1, -2) is created. Point : (2, -1) is created. Point : (0, 0) is created. Point : (0, 0) ========================= Point : (0, 0) is created. Point : (1, 1) is created. Line : (0, 0) to (1, 1) is created. Line : (0, 0) to (1, 1) Line : (0, 0) to (1, 1) is erased. Point : (1, 1) is erased. Point : (0, 0) is erased. ========================= Point : (1, 1) is created. Point : (2, 3) is created. Line : (1, 1) to (2, 3) is created. Line : (1, 1) to (2, 3) Line : (1, 1) to (2, 3) is erased. Point : (2, 3) is erased. Point : (1, 1) is erased. ========================= Point : (2, 3) is created. Point : (4, 5) is created. Line : (2, 3) to (4, 5) is created. Line : (2, 3) to (4, 5) Line : (2, 3) to (4, 5) is erased. Point : (4, 5) is erased. Point : (2, 3) is erased. ========================= Point : (0, 1) is created. Point : (1, 0) is created. Line : (0, 1) to (1, 0) is created. Line : (0, 1) to (1, 0) Line : (0, 1) to (1, 0) is erased. Point : (1, 0) is erased. Point : (0, 1) is erased. ========================= Point : (1, -2) is copied. Point : (2, -1) is copied. Line : (1, -2) to (2, -1) is created. Point : (1, -2) is copied. Point : (0, 0) is copied. Line : (1, -2) to (0, 0) is created. Point : (2, -1) is copied. Point : (0, 0) is copied. Line : (2, -1) to (0, 0) is created. Point : (0, 0) is copied. Point : (2, -1) is copied. Line : (0, 0) to (2, -1) is created. Line : (1, -2) to (2, -1) Line : (1, -2) to (0, 0) Line : (2, -1) to (0, 0) Line : (0, 0) to (2, -1) Line : (0, 0) to (2, -1) is erased. Point : (2, -1) is erased. Point : (0, 0) is erased. Line : (2, -1) to (0, 0) is erased. Point : (0, 0) is erased. Point : (2, -1) is erased. Line : (1, -2) to (0, 0) is erased. Point : (0, 0) is erased. Point : (1, -2) is erased. Line : (1, -2) to (2, -1) is erased. Point : (2, -1) is erased. Point : (1, -2) is erased. Point : (0, 0) is erased. Point : (2, -1) is erased. Point : (1, -2) is erased.

HINT

Append Code

int main()
{
    char c;
    int num, i;
    double x1, x2, y1, y2;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    for(i = 1; i <= num; i++)
    {
        std::cout<<"=========================\n";
        std::cin>>x1>>c>>y1>>x2>>c>>y2;
        Line line(x1, y1, x2, y2);
        line.show();
    }
    std::cout<<"=========================\n";
    Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
    l1.show();
    l2.show();
    l3.show();
    l4.show();
}
 
代码
#include <iostream>
 
using namespace std;
 
class Point
{
    double x,y;
    friend class Line;
    public:
    Point(double xx=0,double yy=0):x(xx),y(yy)
    {
        cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
    }
    ~Point()
    {
        cout<<"Point : ("<<x<<", "<<y<<") is erased."<<endl;
    }
    void show()
    {
        cout<<"Point : ("<<x<<", "<<y<<")"<<endl;
    }
    Point(const Point  & pl )
    {
        x=pl.x;
        y=pl.y;
        cout<<"Point : ("<<x<<", "<<y<<") is copied."<<endl;
    }
};
class Line
{
    Point p1,p2;
friend class Point;
    public:
        Line(double x1,double x2,double x3,double x4):p1(x1,x2),p2(x3,x4)
        {
            cout<<"Line : ("<<x1<<", "<<x2<<") to ("<<x3<<", "<<x4<<") is created."<<endl;
        }
        Line(Point &p,Point &q):p1(p),p2(q)
        {
            cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;
        }
        ~Line()
        {
            cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<endl;
        }
        void show()
        {
            cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<")"<<endl;
        }
};
 
 
int main()
{
    char c;
    int num, i;
    double x1, x2, y1, y2;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    for(i = 1; i <= num; i++)
    {
        std::cout<<"=========================\n";
        std::cin>>x1>>c>>y1>>x2>>c>>y2;
        Line line(x1, y1, x2, y2);
        line.show();
    }
    std::cout<<"=========================\n";
    Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
    l1.show();
    l2.show();
    l3.show();
    l4.show();
}

Problem C: 平面上的点和线——Point类、Line类 (III)的更多相关文章

  1. Problem E: 平面上的点和线——Point类、Line类 (V)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  2. Problem D: 平面上的点和线——Point类、Line类 (IV)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  3. Problem B: 平面上的点和线——Point类、Line类 (II)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  4. Problem A: 平面上的点和线——Point类、Line类 (I)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  5. Problem F: 平面上的点——Point类 (VI)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  6. Problem E: 平面上的点——Point类 (V)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  7. Problem D: 平面上的点——Point类 (IV)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  8. Problem C: 平面上的点——Point类 (III)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  9. Problem B: 平面上的点——Point类 (II)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

随机推荐

  1. 搭建openstack环境时出现的问题

    penstack环境搭建程度(安装完keystone) 然后运行 openstack domain create --description "An Example Domain" ...

  2. Http 状态码:

    消息 100 Continue 101 Switching Protocols 102 Processing 成功 200 OK 201 Created 202 Accepted 203 Non-Au ...

  3. DAY18 常用模块(二)

    一.随机数:RANDOM 1.(0,1)小数:random.random() 2.[1,10]整数:random.randint(1,10) 3.[1,10)整数:random.randrang(1, ...

  4. postgres 11 单实例最大支持多少个database?

    有人在pg8时代(10年前)问过,当时说10000个没问题,而且每个db会在/base下建立1个文件夹, 文件ext3只支持32000个子文件夹,所以这是上限了. 而现在早就ext4了,根本没有限制了 ...

  5. mybatis 动态添加表,查看表,添加数据

    1.动态添加表 mapper int dropExistTable(@Param("tableName") String tableName);//自动创建数据表 映射文件 < ...

  6. Lab 10-2

    The file for this lab is Lab10-02.exe. Questions and Short Answers Does this program create any file ...

  7. vmware虚拟机安装vmware tools

    为了在主机与虚拟机之间共享文件,需要安装vmware tools.在安装vmware tools的过程中遇到了几个坑,在此记录一下. 一.虚拟机关机情况下进行设置.虚拟机->设置->CD/ ...

  8. 手动脱壳—dump与重建输入表(转)

    文章中用到的demo下载地址: http://download.csdn.net/detail/ccnyou/4540254 附件中包含demo以及文章word原稿 用到工具: Ollydbg Lor ...

  9. Google Analytics电子商务篇(Universal版)

    Google Analytics是一款用于统计分析网站流量.浏览行为,可用于衡量用户与您网站的互动情况的全新方式.最近刚接触不久,发现其功能真的十分强大,记录下电子商务配置方法.(新手,老鸟勿喷) G ...

  10. 局域网内Ping不通

    局域网ping不通, 原来不可忽视这步......... 通常,经常在局域网里面,为了检测网络是否顺畅,都会ping一下IP,如果网络正常,就可以上网或者远程处理其他故障.但是会出现ping别人的主机 ...