ProblemI平面上的点和线分析_第1页
ProblemI平面上的点和线分析_第2页
ProblemI平面上的点和线分析_第3页
ProblemI平面上的点和线分析_第4页
ProblemI平面上的点和线分析_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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

2、对象。Point:x()方法:取x坐标。Point:y()方法:取y坐标。Line:show()方法:按格式输出Line对象。Line:SetLine(double, double, double, double)方法:设置Line对象起点的x,y坐标(第一个和第二参数)和终点的x,y坐标(第三个和第四个坐标),并返回本对象Line:SetLine(const Point &, const Point &)方法:设置Line对象的起点(第一个参数)和终点(第二个坐标),并返回本对象Line:SetLine(const Line&)方法:设置Line对象,复制参数的坐标,并返回本对象Line:r

3、eadLine()方法:从标准输入上读入坐标,格式见SampleLine:start()方法:取Line的起点Line:end()方法:取Line的终点Line:setStart()方法:设置Line的起点Line:setEnd()方法:设置Line的终点以下三个函数用于输出Line对象,格式同sampleshowLineCoordinate(const Line&)showLinePoint(const Line&)showLine(const Line&)Input输入的第一行为N,表示后面有N行测试样例。每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空

4、格分开,x和y的值都在double数据范围内。Output输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。C语言的输入输出被禁用。Sample Input40,0 1,11,1 2,32,3 4,50,1 1,0Sample OutputPoint : (1, -2) is created.Point : (2, -1) is created.Point : (0, 0) is created.Point : (0, 0)Point : (0, 0) is created.Point : (

5、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

6、) 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

7、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 : (1, -2) is copied.Point : (2, -1) is copied.Line : (1, -2) to (2, -1) is copied.Line : (1, -2) to (2, -1)Line : Point : (1, -2) to Point

8、: (0, 0)Line : Point : (1, -2) to Point : (2, -1)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 : (1, -2) to (2, -1) is erased.Point : (2, -1) is erased.Point : (1, -2) is erased.Line : (1, -2) to (0, 0) is erased.Point : (0, 0) is

9、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,

10、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.Line : (0, 0) to (2, -1) is erased.Point : (2, -1) is erased.Point : (0, 0) is erased.Point : (0, 0) is erased.Point : (2, -1) is erased.Point

11、: (1, -2) is erased.HINTAppend Code#include#includeusing namespace std;class Pointdouble ax,ay;public:friend class Line;Point(Point &a)ax=a.ax;ay=a.ay;coutPoint : (ax, ay) is copied.endl;Point(double x=0,double y=0):ax(x),ay(y)coutPoint : (ax, ay) is created.endl;/Point():ax(0),ay(0)Point()coutPoint

12、 : (ax, ay) is erased.endl;double x()const return ax;double y()constreturn ay;void showNoEndOfLine()constcoutPoint : (ax, ay);void show()coutPoint : (ax, ay)endl;class LinePoint p,q;public:Line():p(0,0),q(0,0)coutLine : (p.ax, p.ay) to (q.ax, q.ay) is created.endl;Line ( Line &a):p(a.p),q(a.q)coutLi

13、ne : (p.ax, p.ay) to (q.ax, q.ay) is copied.endl;Line(Point &a,Point &b):p(a),q(b)coutLine : (p.ax, p.ay) to (q.ax, q.ay) is created.endl;Line(double x1,double y1,double x2,double y2):p(x1,y1),q(x2,y2)coutLine : (p.ax, p.ay) to (q.ax, q.ay) is created.endl;Line()coutLine : (p.ax, p.ay) to (q.ax, q.a

14、y) is erased.p.axcp.ayq.axcq.ay;Line&setLine(Line &a)*this=a;return *this;Line&setLine(Point &a,Point &b)p=a;q=b;return *this;const Point &start()constreturn p;const Point &end()constreturn q;void setStart(Point &a)p=a;void setEnd(Point &b)q=b;void show()const coutLine : (p.ax, p.ay) to (q.ax, q.ay)

15、endl;void showLineCoordinate(const Line& line)std:coutLine : ;std:cout(line.start().x(), line.start().y();std:cout to ;std:cout(line.end().x(), line.end().y();std:coutstd:endl;void showLinePoint(const Line& line)std:coutLine : ;line.start().showNoEndOfLine();std:cout to ;line.end().showNoEndOfLine();std:coutnum;Line linenum +

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论