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 : (0, 0) is created. Line : (0, 0) to (0, 0) is created. Point : (0, 0) is created. Point : (0, 0) is created. Line : (0, 0) to (0, 0) is created. Point : (0, 0) is created. Point : (0, 0) is created. Line : (0, 0) to (0, 0) is created. Point : (0, 0) is created. Point : (0, 0) is created. Line : (0, 0) to (0, 0) is created. ========================= Line : (0, 0) to (1, 1) ========================= Line : (1, 1) to (2, 3) ========================= Line : (2, 3) to (4, 5) ========================= Line : (0, 1) to (1, 0) ========================= 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. Line : (0, 1) to (1, 0) is erased. Point : (1, 0) is erased. Point : (0, 1) is erased. Line : (2, 3) to (4, 5) is erased. Point : (4, 5) is erased. Point : (2, 3) is erased. Line : (1, 1) to (2, 3) is erased. Point : (2, 3) is erased. Point : (1, 1) is erased. Line : (0, 0) to (1, 1) is erased. Point : (1, 1) is erased. Point : (0, 0) 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;
    Line line[num];
    for(i = 0; i < num; i++)
    {
        std::cout<<"=========================\n";
        std::cin>>x1>>c>>y1>>x2>>c>>y2;
        line[i].SetLine(x1, y1, x2, y2);
        line[i].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=0,double x2=0,double x3=0,double x4=0):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;
        }
        void SetLine(double a,double b,double c,double d)
        {
            p1.x=a;
            p1.y=b;
            p2.x=c;
            p2.y=d;
        }
};
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;
    Line line[num];
    for(i = 0; i < num; i++)
    {
        std::cout<<"=========================\n";
        std::cin>>x1>>c>>y1>>x2>>c>>y2;
        line[i].SetLine(x1, y1, x2, y2);
        line[i].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 D: 平面上的点和线——Point类、Line类 (IV)的更多相关文章

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

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

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

    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. javascript实现游戏贪吃蛇

    1.设计蛇:属性有宽.高.方向.状态(有多少节),方法:显示,跑 2.设计食物:属性宽.高 3.显示蛇:根据状态向地图里加元素 4.蛇跑起来:下一节到前一节的位置,蛇头根据方向变,删除原来的蛇,新建蛇 ...

  2. vue--监听器

    vue当中的属性,侦听器watch computed可以根据数据的变化而变化,而watch也具备同样的功能 既然这么相似,那么两者的区别是什么呢 首先是执行顺序上有一些细微差别,dom加载完成后将立即 ...

  3. SpringCloud问题解决:spring-cloud-eureka启动出错Cannot execute request on any known server

    场景: 在启动eureka server时,出现以下错误: com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectExce ...

  4. ExtJs写本地ArrayStore,ComboBox调用

    1.自定义本地ArrayStore var sCurStore = new Ext.data.ArrayStore({ //设备状态store fields: ["ckey", & ...

  5. CF Manthan, Codefest 16 B. A Trivial Problem

    数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k  输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想  阶乘 emmm  1*2*3*4*5*6*7*8*9 ...

  6. Android人脸识别Demo竖屏YUV方向调整和图片保存

    本博客包含三个常用方法,用于盛开Android版人脸识别Demo中竖屏使用时送入yuv数据,但一直无法识别的情况. 1.首先可以尝试顺时针旋转90°或270°,然后送入识别SDK. 2.旋转方向后依然 ...

  7. Java并发编程的艺术· 笔记(1)

    目录 1.volatile的原理 2.Synchonized 3.无锁-偏向锁-轻量级锁-重量级锁 4.Java实现原子操作 1.volatile的原理 如何保持可见性: 1)将当前处理器缓存行的数据 ...

  8. MIUI8系统完整刷入开发版开启root权限的经验

    小米的机器不同手机型号一般情况官网都提供两个不同的安卓系统版本,可分为稳定版和开发版,稳定版没有提供root超级权限管理,开发版中就支持了root超级权限,很多情况我们需要使用的一些功能强大的APP, ...

  9. JMETER-01

    jmter安装 1.Linxu安装: 步骤:下载JMeter包-->解压包-->赋权限-->配置环境变量-->测试服务 1.下载:wget http://mirrors.hus ...

  10. SWUST OJ(599)

    拉丁方阵 #include <iostream> #include <cstdlib> using namespace std; int main() { int n; cin ...