Problem A: 立体空间中的点(I)

xiaoxiao2021-02-28  46

HomeWeb BoardProblemSetStandingStatusStatistics

Problem A: 立体空间中的点(I)

Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 2462   Solved: 1945 [ Submit][ Status][ Web Board]

Description

设计一个平面上的点Point类和3维的点Point_3D类,满足Point_3D类继承自Point类,用于读取输入的数据,输出所构造的两种点的坐标。 设计Point类需支持一下操作: Point::Point()无参构造。 Point::Point(double,double)两个坐标参数构造。 Point::showPoint()按格式输出Point对象 设计Point_3D类需支持一下操作: Point_3D::Point_3D()无参构造。 Point_3D::Point_3D(double,double,double)三个坐标参数构造。 Point_3D::showPoint()按格式输出Point_3D对象。 ----------------------------------------------------------------------------- 你设计Point类和Point_3D类,使得main()函数能够正确运行。 函数调用格式见append.cc。 append.cc中已给出main()函数。

Input

输入的第一个整数n,表示有n组测试数据,后面的输入每行为一组测试数据。每组测试数据的第一行是一个整数m,m有两种取值:2、3;m为2时,后面有两个浮点数x、y,表示一个平面上的点的坐标(x,y);m为3时后面有3个浮点数x、y、z,表示一个3维的点的坐标(x,y,z)。

Output

每组测试数据对应一行输出。 若输入为平面上的点,则输出:“2D Point (x,y)”,x和y为输入的坐标值。 若输入为3维的点,则输出:“3D Point (x,y,y)”,x、y和z为输入的坐标值。

Sample Input

53 1 2 33 0 0 02 -1 13 -1 -1 -12 0 0

Sample Output

3D Point (1,2,3)3D Point (0,0,0)2D Point (-1,1)3D Point (-1,-1,-1)2D Point (0,0)

HINT

Append Code

append.cc, [ Submit][ Status][ Web Board]

한국어<  中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin

#include <iostream> using namespace std; class Point { public: void showPoint() const { cout << "2D Point (" << x << "," << y <<")" << endl; } public: Point( ) { } Point(int xx, int yy) : x(xx), y(yy) { } protected: int x, y; }; class Point_3D : public Point { public: void showPoint( ) const { cout << "3D Point (" << x << "," << y << "," << z << ")" << endl; } public: Point_3D() { } Point_3D(int xx, int yy, int zz):Point(xx,yy), z(zz) { } private: int z; }; int main() { int cases; cin>>cases; for(int i = 1; i <= cases; i++) { double x, y, z; int point_type; cin>>point_type; if(point_type == 2) { cin>>x>>y; Point p(x, y); p.showPoint(); } if(point_type == 3) { cin>>x>>y>>z; Point_3D p(x, y, z); p.showPoint(); } } }
转载请注明原文地址: https://www.6miu.com/read-78826.html

最新回复(0)