zoukankan      html  css  js  c++  java
  • YTU 2958: 代码填充--雨昕学画画

    2958: 代码填充--雨昕学画画

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 156  解决: 102

    题目描述

    雨昕开始学画水彩画,老师给雨昕一个形状(Shape)类,雨昕在Shape类的基础上画矩形(Rectangle)类。Rectangle类继承Shape类,增加了double类型的宽(width)和高(height)。矩形类坚持用自己的面积area()。但是雨昕不会为Rectangle类写构造函数和成员函数,请帮助雨昕完成Rectangle类。

    注:本题只需要提交填写部分的代码,请按照C++方式提交。

    #include<iostream>
    #include<iomanip>
    using namespace std;
    class Shape
    {
    public:
        Shape();
        Shape(int c);
        int getcolor();
        double area();
    protected:
        int color;
    };
    Shape::Shape()
    {
        color=0;
    }
    Shape::Shape(int c)
    {
        color=c;
    }
    int Shape::getcolor()
    {
        return color;
    }
    double Shape::area()
    {
        return 0;
    }
    class Rectangle:public Shape
    {
    public:
        Rectangle(int c,double w,double h);
        double getwidth();
        double getheight();
        double area();
    protected:
        double height;
        double width;
    };

    /*

    请在该部分补充缺少的代码
    */

    int main()
    {
        int color;
        double height,width;
        cin>>color>>height>>width;
        Rectangle rect=Rectangle(color,height,width);
        cout<<setiosflags(ios::fixed)<<setprecision(0);
        cout<<"Rectangle area:"<<rect.area()<<endl;
        return 0;
    }

    输入

    水彩画的颜色,Rectangle类的宽(width)和高(height)。

    输出

    矩形的面积。

    样例输入

    1 2 3

    样例输出

    Rectangle area:6

    你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

    #include<iostream>
    #include<iomanip>
    using namespace std;
    class Shape
    {
    public:
        Shape();
        Shape(int c);
        int getcolor();
        double area();
    protected:
        int color;
    };
    Shape::Shape()
    {
        color=0;
    }
    Shape::Shape(int c)
    {
        color=c;
    }
    int Shape::getcolor()
    {
        return color;
    }
    double Shape::area()
    {
        return 0;
    }
    class Rectangle:public Shape
    {
    public:
        Rectangle(int c,double w,double h);
        double getwidth();
        double getheight();
        double area();
    protected:
        double height;
        double width;
    };
    Rectangle::Rectangle(int c,double w,double h)
    {
        color=c,height=w,width=h;
    }
    double Rectangle::area()
    {
        return height*width;
    }
    int main()
    {
        int color;
        double height,width;
        cin>>color>>height>>width;
        Rectangle rect=Rectangle(color,height,width);
        cout<<setiosflags(ios::fixed)<<setprecision(0);
        cout<<"Rectangle area:"<<rect.area()<<endl;
        return 0;
    }

  • 相关阅读:
    SpringMvc 大概流程分析
    HandlerMethodArgumentResolver 参数解析器
    linux 技巧:使用 screen 管理你的远程会话
    CentOS Linux解决Device eth0 does not seem to be present
    php连接oracle oracle开启扩展
    关于linux一些备份、还原,压缩,归档的命令
    Sphinx学习之sphinx的安装篇
    linux wget 命令用法详解(附实例说明)
    Linux的bg和fg命令
    linux中ctrl+z和ctrl+c的区别
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989639.html
Copyright © 2011-2022 走看看