Problem A: 立体空间中的点(I)
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1413 Solved: 1104
[ 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
5 3 1 2 3 3 0 0 0 2 -1 1 3 -1 -1 -1 2 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
#include<iostream>
#include<set>
#include<iterator>
#include<string>
#include<set>
#include<queue>
#include<list>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<map>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<sstream>
using namespace std;
class Point
{
protected:
int x,y;
public:
Point():x(0),y(0){}
Point(double a,double b):x(a),y(b){}
void showPoint(){cout<<"2D Point ("<<x<<","<<y<<")"<<endl;}
};
class Point_3D:public Point
{
protected:
int z;
public:
Point_3D():z(0){}
Point_3D(double a,double b,double c):Point(a,b),z(c){}
void showPoint(){cout<<"3D Point ("<<x<<","<<y<<","<<z<<")"<<endl;}
};
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();
}
}
}