zoukankan      html  css  js  c++  java
  • 实验8:Problem A: 立体空间中的点(I)

    Home Web Board ProblemSet Standing Status Statistics
     
    Problem A: 立体空间中的点(I)

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

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 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

     

    Append Code

    [Submit][Status][Web Board]
    #include<iostream>
    using namespace std;
    class Point{
    protected:
    int x,y;
    public:
    Point():x(0),y(0){}
    Point(double xx,double yy):x(xx),y(yy){}
    void showPoint(){cout<<"2D Point ("<<x<<","<<y<<")"<<endl;}
    };
    class Point_3D:public Point{
    protected:
    int z;
    public:
    Point_3D():z(0){}
    Point_3D(double xx,double yy,double zz):Point(xx,yy),z(zz){}
    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();
            }
        }
    }
    向代码最深处出发~!
  • 相关阅读:
    JavaWeb chapter 8 过滤器
    JavaWeb Chapter 7 监听器
    JavaWeb chapter6 对象作用域
    JavaWeb chapeter 5 Web应用程序状态管理
    JavaWeb chapter 4 Servlet处理HTTP请求
    JavaWeb chapter3 Servlet处理HTTP响应
    JavaWeb chapter 2 Servlet
    蒙版
    CSS样式,雪碧,图片替换,渐变小析
    本地存储之简单存储
  • 原文地址:https://www.cnblogs.com/auto1945837845/p/5425579.html
Copyright © 2011-2022 走看看