Description

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

Input

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

Output

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

Sample Input

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

Sample Output

Point : (0, 0) Line : (0, 0) to (1, 1) is created. Line : (0, 0) to (1, 1) Line : (0, 0) to (1, 1) is erased. Line : (1, 1) to (2, 3) is created. Line : (1, 1) to (2, 3) Line : (1, 1) to (2, 3) is erased. Line : (2, 3) to (4, 5) is created. Line : (2, 3) to (4, 5) Line : (2, 3) to (4, 5) is erased. Line : (0, 1) to (1, 0) is created. Line : (0, 1) to (1, 0) Line : (0, 1) to (1, 0) is erased. Line : (1, -2) to (2, -1) is created. Line : (1, -2) to (0, 0) is created. Line : (2, -1) to (0, 0) is created. 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. Line : (2, -1) to (0, 0) is erased. Line : (1, -2) to (0, 0) is erased. Line : (1, -2) to (2, -1) 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::cin>>x1>>c>>y1>>x2>>c>>y2;
        Line line(x1, y1, x2, y2);
        line.show();
    }
    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
{
    friend class Line;
    double x,y;
     public:
    Point():x(0),y(0){}
    Point(double a,double b):x(a),y(b){}
    void show()
    {
             cout<<"Point : ("<<x<<", "<<y<<")"<<endl;
    }
};
class Line
{
    friend class Point;
    Point p1,p2;
public:
    Line(double a,double b,double c,double d):p1(a,b),p2(c,d)
    {
        cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") 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;
    }
    void show()
    {
        cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<")"<<endl;
    }
    ~Line()
    {
        cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<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::cin>>x1>>c>>y1>>x2>>c>>y2;
        Line line(x1, y1, x2, y2);
        line.show();
    }
    Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
    l1.show();
    l2.show();
    l3.show();
    l4.show();
}

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

  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 C: 平面上的点和线——Point类、Line类 (III)

    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. tf.InteractiveSession()和tf.Session()

    tf.InteractiveSession()适合用于python交互环境 tf.Session()适合用于源代码中 1.tf.InteractiveSession() 直接用eval()就可以直接获 ...

  2. https://scrapingclub.com/exercise/basic_login/

    遇到的问题:csrftoken cfduid 是在request.headers里面的,一直在找怎么在scrapy里get request.header,从scrapy shell ,then fet ...

  3. Apriori

    基本概念 项与项集:设itemset={item1, item_2, …, item_m}是所有项的集合,其中,item_k(k=1,2,…,m)成为项.项的集合称为项集(itemset),包含k个项 ...

  4. Axis2的简单配置(完整版)

    Axis2的简单配置(终结版) 1.axis2 下载地址 axis2-1.6.2-bin.zip http://mirror.esocc.com/apache//axis/axis2/java/cor ...

  5. 泛型-----键值对----映射 hashmap--entry中key value 链表

    connection map 集合框架 * java.util.Collection *集合与数组相似,也是可以保存一组元素,并且提供了操作元素的相关方法. *collection是所有集合的顶级接口 ...

  6. Java字节码浅析(二)

    英文原文链接,译文链接,原文作者:James Bloom,译者:有孚 条件语句 像if-else, switch这样的流程控制的条件语句,是通过用一条指令来进行两个值的比较,然后根据结果跳转到另一条字 ...

  7. JS设计模式(13)状态模式

    什么是状态模式? 定义:将事物内部的每个状态分别封装成类,内部状态改变会产生不同行为. 主要解决:对象的行为依赖于它的状态(属性),并且可以根据它的状态改变而改变它的相关行为. 何时使用:代码中包含大 ...

  8. 学习requests_html

    一.获取页面上的所有链接. from requests_html import HTMLSession session=HTMLSession() r=session.get('https://new ...

  9. 单元测试系列之三:JUnit单元测试规范

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6762032.html Junit测试代 ...

  10. 误操作yum导致error: rpmdb

    error: cannot open Packages index using db5 -  (-30973) error: cannot open Packages database in /var ...