代码填充--雨昕学画画

2020年1月17日 1269点热度 0人点赞 0条评论

代码填充--雨昕学画画

时间: 1ms        内存:128M

描述:

雨昕开始学画水彩画,老师给雨昕一个形状(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

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论