C++实验.docx
- 文档编号:26083406
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:39
- 大小:29.30KB
C++实验.docx
《C++实验.docx》由会员分享,可在线阅读,更多相关《C++实验.docx(39页珍藏版)》请在冰豆网上搜索。
C++实验
ProblemA:
平面上的点——Point类(I)
TimeLimit:
1Sec MemoryLimit:
4MB
Submit:
6823 Solved:
2994
[Submit][Status][WebBoard]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。
现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和show()方法。
接口描述:
Point:
:
show()方法:
按输出格式输出Point对象。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
输出为多行,每行为一个点,X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。
每个坐标的输出精度为最长16位。
输出格式见sample。
C语言的输入输出被禁用。
SampleInput
1,23,32,1
SampleOutput
Point:
(1,2)Point:
(3,3)Point:
(2,1)Point:
(0,0)
HINT
注意精度控制,C语言的输入输出被禁用。
AppendCode
append.cc,
#include
#include
usingnamespacestd;
classPoint
{
private:
doublex,y;
public:
Point(doublexx,doubleyy)
{
x=xx;
y=yy;
}
Point()
{
x=y=0;
}
voidshow()
{
cout< '<<""<<'('< } }; intmain() { charc; doublea,b; Pointq; while(std: : cin>>a>>c>>b) { Pointp(a,b); p.show(); } q.show(); } ProblemB: 平面上的点——Point类(II) TimeLimit: 1Sec MemoryLimit: 4MB Submit: 5743 Solved: 2906 [Submit][Status][WebBoard] Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。 现在我们封装一个“Point类”来实现平面上的点的操作。 根据“append.cc”,完成Point类的构造方法和show()方法,输出各Point对象的构造和析构次序。 接口描述: Point: : show()方法: 按输出格式输出Point对象。 Input 输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。 Output 输出每个Point对象的构造和析构行为。 对每个Point对象,调用show()方法输出其值: X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。 每个坐标的输出精度为最长16位。 输出格式见sample。 C语言的输入输出被禁用。 SampleInput 1,23,32,1 SampleOutput Point: (0,0)iscreated.Point: (1,2)iscreated.Point: (1,2)Point: (1,2)iserased.Point: (3,3)iscreated.Point: (3,3)Point: (3,3)iserased.Point: (2,1)iscreated.Point: (2,1)Point: (2,1)iserased.Point: (0,0)iscopied.Point: (1,1)iscreated.Point: (0,0)Point: (1,1)Point: (0,0)Point: (1,1)iserased.Point: (0,0)iserased.Point: (0,0)iserased. HINT 思考构造函数、拷贝构造函数、析构函数的调用时机。 AppendCode append.cc, #include #include usingnamespacestd; classPoint { private: doublex,y; public: Point(doublexx,doubleyy) { x=xx;y=yy; cout< ("< } Point() { x=y=0; cout< ("< } Point(doublexx) { x=y=xx; cout< ("< } Point(constPoint&p) { x=p.x; y=p.y; cout< ("< } ~Point() { cout< ("< } voidshow(); }; voidPoint: : show() { cout< ("< } intmain() { charc; doublea,b; Pointq; while(std: : cin>>a>>c>>b) { Pointp(a,b); p.show(); } Pointq1(q),q2 (1); q1.show(); q2.show(); q.show(); } ProblemC: 平面上的点——Point类(III) TimeLimit: 1Sec MemoryLimit: 4MB Submit: 3819 Solved: 2642 [Submit][Status][WebBoard] Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。 现在我们封装一个“Point类”来实现平面上的点的操作。 根据“append.cc”,完成Point类的构造方法和show()方法,输出各Point对象的构造和析构次序。 实现showPoint()函数。 接口描述: showPoint()函数按输出格式输出Point对象,调用Point: : show()方法实现。 Point: : show()方法: 按输出格式输出Point对象。 Input 输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。 Output 输出每个Point对象的构造和析构行为。 showPoint()函数用来输出(通过参数传入的)Point对象的值: X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。 每个坐标的输出精度为最长16位。 输出格式见sample。 C语言的输入输出被禁用。 SampleInput 1,23,32,1 SampleOutput Point: (0,0)iscreated.Point: (1,2)iscreated.Point: (1,2)iscopied.Point: (1,2)Point: (1,2)iserased.Point: (1,2)iserased.Point: (3,3)iscreated.Point: (3,3)iscopied.Point: (3,3)Point: (3,3)iserased.Point: (3,3)iserased.Point: (2,1)iscreated.Point: (2,1)iscopied.Point: (2,1)Point: (2,1)iserased.Point: (2,1)iserased.Point: (0,0)iscopied.Point: (1,1)iscreated.Point: (0,0)iscopied.Point: (1,1)iscopied.Point: (0,0)iscopied.Point: (0,0)Point: (1,1)Point: (0,0)Point: (0,0)iserased.Point: (1,1)iserased.Point: (0,0)iserased.Point: (1,1)iserased.Point: (0,0)iserased.Point: (0,0)iserased. HINT 思考构造函数、拷贝构造函数、析构函数的调用时机。 AppendCode append.cc, #include #include usingnamespacestd; classPoint { protected: doublex,y; public: Point(doublea,doubleb) { x=a; y=b; cout< ("< } Point() { x=y=0; cout< ("< } Point(doublea) { x=y=a; cout< ("< } Point(constPoint&p) { x=p.x; y=p.y; cout< ("< } voidshow() { cout< ("< } ~Point() { cout< ("< } }; voidshowPoint(Pointa) { a.show(); } voidshowPoint(Pointa,Pointb,Pointc) { a.show(); b.show(); c.show(); } intmain() { charc; doublea,b; Pointq; while(std: : cin>>a>>c>>b) { Pointp(a,b); showPoint(p); } Pointq1(q),q2 (1); showPoint(q1,q2,q); } ProblemD: 平面上的点——Point类(IV) TimeLimit: 1Sec MemoryLimit: 4MB Submit: 4444 Solved: 2521 [Submit][Status][WebBoard] Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。 现在我们封装一个“Point类”来实现平面上的点的操作。 根据“append.cc”,完成Point类的构造方法和show()、showCounter()、showSumOfPoint()方法;实现showPoint()函数。 接口描述: showPoint()函数: 按输出格式输出Point对象,调用Point: : show()方法实现。 Point: : show()方法: 按输出格式输出Point对象。 Point: : showCounter()方法: 按格式输出当前程序中Point对象的计数。 Point: : showSumOfPoint()方法: 按格式输出程序运行至当前存在过的Point对象总数。 Input 输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。 Output 对每个Point对象,调用show()方法输出其值,或者用showPoint()函数来输出(通过参数传入的)Point对象的值: X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。 每个坐标的输出精度为最长16位。 调用用showCounter()方法和showSumOfPoint()输出Point对象的计数统计,输出格式见sample。 C语言的输入输出被禁用。 SampleInput 1,23,32,1 SampleOutput Point: (1,2)Current: 2points.Point: (3,3)Current: 2points.Point: (2,1)Current: 2points.Intotal: 4points.Current: 3points.Point: (0,0)Point: (1,1)Point: (0,0)Intotal: 6points. HINT 对象计数通过静态成员来实现 AppendCode append.cc, #include #include usingnamespacestd; classPoint { private: doublex,y; staticintn,m; public: Point(doublexx,doubleyy) { x=xx; y=yy; n++;m++; } Point() { x=y=0; n++;m++; } Point(doublexx) { x=y=xx; n++;m++; } Point(constPoint&p) { x=p.x; y=p.y; n++;m++; } ~Point() { n--; } voidshow(); voidshowPoint(); staticvoidshowCounter() { cout<<"Current: "< } staticvoidshowSumOfPoint() { cout<<"Intotal: "< } }; voidPoint: : show() { cout< ("< } voidshowPoint(Point&p,Point&q,Point&r) { p.show(); q.show(); r.show(); } intPoint: : n=0; intPoint: : m=0; intmain() { charc; doublea,b; Pointq; while(std: : cin>>a>>c>>b) { Pointp(a,b); p.show(); p.showCounter(); } q.showSumOfPoint(); Pointq1(q),q2 (1); Point: : showCounter(); showPoint(q1,q2,q); Point: : showSumOfPoint(); } ProblemE: 平面上的点——Point类(V) TimeLimit: 1Sec MemoryLimit: 4MB Submit: 5432 Solved: 2096 [Submit][Status][WebBoard] Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。 现在我们封装一个“Point类”来实现平面上的点的操作。 根据“append.cc”,完成Point类的构造方法和接口描述中的方法。 接口描述: showPoint()函数: 按输出格式输出Point对象。 Point: : show()方法: 按输出格式输出Point对象。 Point: : showSumOfPoint()方法: 按格式输出程序运行至当前存在过的Point对象总数。 Point: : x()方法: 取x坐标。 Point: : y()方法: 取y坐标。 Point: : x(double)方法: 传参数设置x坐标并返回。 Point: : y(double)方法: 传参数设置y坐标并返回。 Point: : getX()方法: 取x坐标。 Point: : getY()方法: 取y坐标。 Point: : setX()方法: 传参数设置x坐标并返回。 Point: : setY()方法: 传参数设置y坐标并返回。 Point: : setPoint(double,double)方法: 设置Point对象的x坐标(第一个参数)和y坐标(第二个参数)并返回本对象 Input 输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。 Output 用ShowPoint()函数来输出(通过参数传入的)Point对象的值或坐标值: X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。 每个坐标的输出精度为最长16位。 对每个Point对象,调用show()方法输出其值,输出格式与ShowPoint()函数略有不同: “Point[i]: ”,i表示这是程序运行过程中第i个被创建的Point对象。 调用showSumOfPoint()输出Point对象的计数统计,输出格式见sample。 C语言的输入输出被禁用。 SampleInput 1,23,32,1 SampleOutput Point: (1,2)Point: (3,3)Point: (2,1)Point: (1,1)Point: (4,-3)==========gorgeousseparator==========Point[1]: (1,0)Point[2]: (3,3)Point[3]: (0,0)Point[4]: (4,-3)Point[64]: (1,0)Point[64]: (1,0)==========gorgeousseparator==========Intotal: 66points. HINT 传递和返回引用是不构造新对象的。 给函数正确的返回值。 AppendCode append.cc, #include #include usingnamespacestd; classPoint { private: doublea,b; staticintn; public: inti; doublex(){returnthis->a;} doubley(){returnthis->b;} doublex(doubleaa){a=aa;returna;} doubley(doublebb){b=bb;returnb;} doublegetX(){returna;} doublegetY(){returnb;} doublesetX(doubleaa){a=aa;returna;} doublesetY(doublebb){b=bb;returnb;} Point&setPoint(doubleaa,doublebb) { a=aa; b=bb; return*this; } Point() { a=b=0; n++; i=n; } Point(doubleaa) { a=b=aa; n++; i=n; } Point(doubleaa,doublebb) { a=aa; b=bb; n++; i=n; } Point(constPoint&p) { a=p.a; b=p.b; n++; i=n; } ~Point() { } staticvoidshowSumOfPoint() { cout<<"Intotal: "< } voidshow() { cout<<"Point["< ("< } }; intPoint: : n=0; voidShowPoint(Pointp) { cout< : setprecision(16)<<"Point: ("< } voidShowPoint(doublex,doubley) { Pointp(x,y); cout< : setprecision(16)<<"Point: ("<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 实验