1. 程式人生 > >實驗1:Problem A: 平面上的點和線——Point類、Line類 (I)

實驗1:Problem A: 平面上的點和線——Point類、Line類 (I)

Problem A: 平面上的點和線——Point類、Line類 (I)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2839  Solved: 1783
[Submit][Status][Web Board]

Description

在數學上,平面直角座標系上的點用X軸和Y軸上的兩個座標值唯一確定,兩點確定一條線段。現在我們封裝一個“Point類”和“Line類”來實現平面上的點的操作。 根據“append.cc”,完成Point類和Line類的構造方法和show()方法。 介面描述: 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)
Line : (1, 1) to (2, 3)
Line : (2, 3) to (4, 5)
Line : (0, 1) to (1, 0)
Line : (1, -2) to (2, -1)
Line : (1, -2) to (0, 0)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)

HINT

Append Code

append.cc,
#include<iostream> using namespace std; class Point { private: double x,y; public: Point(){ x = 0; y = 0; } Point(double x1,double y1){ x = x1; y = y1; } void show(){ cout<<"Point : ("<<x<<", "<<y<<")"<<endl; } Point(Point &p){
x = p.x; y = p.y; } double getx() { return x; } double gety(){ return y; } }; class Line { private: Point p,q; public: Line(double a,double b,double c,double d):p(a,b),q(c,d){ } void show(){ cout<<"Line : ("<<p.getx()<<", "<<p.gety()<<") to ("<<q.getx()<<", "<<q.gety()<<")"<<endl; } Line(Point a,Point b):p(a),q(b) {} }; 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: 1327 User: 201501060523 Language: C++ Result: Accepted Time:8 ms Memory:1268 kb ****************************************************************/