Description

小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮。Rectangle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员width和height,求面积的成员函数area()。但是小聪没有为Rectangle类写构造函数和成员函数,请帮助小聪完成Rectangle类。

小强写的文件头和Shape类:

#include<iostream>

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 10000;
}
小聪的测试函数:
int main()
{
Rectangle rr=Rectangle(1,2,3);
cout<<"Rectangle color:"<<rr.getcolor()<<endl
<<"Rectangle width:"<<rr.getwidth()<<endl
<<"Rectangle height:"<<rr.getheight()<<endl
<<"Rectangle area:"<<rr.area()<<endl
<<"Rectangle price:"<<rr.price()<<endl;
return 0;
}
提示:不用提交全部程序,只提交补充部分。

Input

Output

输出小聪创建的矩形的相关数据。

Sample Output

Rectangle color:1Rectangle width:2Rectangle height:3Rectangle area:6Rectangle price:6
#include<iostream>
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 10000;
}
class Rectangle:public Shape
{
public:Rectangle(){}Rectangle(int c,int w,int h):Shape(c),width(w),height(h){}int getwidth();int getheight();int area();int price();
private:int width,height;
};int Rectangle::getwidth()
{return width;}
int Rectangle::getheight()
{return height;}
int Rectangle::area()
{return width*height;}
int Rectangle::price()
{return width+height+color;}
int main(){Rectangle rr=Rectangle(1,2,3);cout<<"Rectangle color:"<<rr.getcolor()<<endl<<"Rectangle width:"<<rr.getwidth()<<endl<<"Rectangle height:"<<rr.getheight()<<endl<<"Rectangle area:"<<rr.area()<<endl<<"Rectangle price:"<<rr.price()<<endl;return 0;
}

[YTU]_2916(Shape系列-2)相关推荐

  1. YTU 2917: Shape系列-3

    2917: Shape系列-3 时间限制: 1 Sec  内存限制: 128 MB 提交: 372  解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...

  2. [YTU]_2920( Shape系列-6)

    Description Shape系列终于快完成了,小聪可以歇一下了.但是这个时候JC和Kitty把自己的矩形和圆形做好,想给小聪比试一下,小聪也不示弱,拿出来自己的做出的三角形和他们一分高下.他们的 ...

  3. [YTU]_2922(Shape系列-8)

    Description 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小聪自力更生创建了Point类,但是他没有写Point类.继承Point类的Circle类.继承Circ ...

  4. [YTU]_2921( Shape系列-7)

    Description 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函数的问题,请大家根据题意,帮助小强完成改动后的Shape类. 小强写的各种类 class Rectang ...

  5. [YTU]_2919( Shape系列-5)

    Description JC和Kitty听说小亮和小华有了Rectangle和Circle并用RsubC类比较了大小,于是想借小亮和小华的Rectangle和Circle来仿制自己的形状,于是JC和K ...

  6. [YTU]_2918( Shape系列-4)

    Description 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状,来看看小聪更爱谁,请完成RsubC类.RsubC类中包括Rectangle类和Circle类的数据成员 ...

  7. [YTU]_2917(Shape系列-3)

    送给小亮的Rectangle类已完成,送给小华Circle类还没有完成.Circle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员radiu ...

  8. [YTU]_2915(Shape系列-1)

    Description 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有整型的数据成员color,求面积的成员函数area().小强针对不知道千奇百怪的Shape如何求面积,于 ...

  9. Android2D绘图一

    View 只是把Graphic 资源(images,shapes,colors,pre-defined animation等等这些Android已经实现的一些画图操作)放入View体系,由系统 来将这 ...

最新文章

  1. 快来支招~程序员怎么哄女朋友? | 每日趣闻
  2. 怎么判断模式窗体打开的窗体名_QtitanRibbon是什么?该怎么用?
  3. brew 安装mysql5.6_mac使用brew安装mysql的坑
  4. [转]OpenGL库介绍
  5. css如何插入动态图,css动态图(作业)
  6. maven构建java web项目(idea开发)
  7. RabbitMQ学习之spring-amqp的重要类的认识
  8. 网易游戏开发工程师笔试题
  9. 开篇 | 揭秘 Flink 1.9 新架构,Blink Planner 你会用了吗?
  10. 【Xamarin挖墙脚系列:mac 终端 常用命令+Mac OS X的快捷键+beamoff 】
  11. 微信小程序 input ,阻止冒泡事件,catchtap的使用
  12. 单片机AD采样的几种算法
  13. STM32单片机实现二维码显示
  14. 一个正整数到 Excel 编号之间的转换
  15. 放弃数学专业跳槽高薪行业,如今他却后悔了
  16. 洛克希德·马丁定义的“杀伤链”
  17. 盘点那些真正能提升工作幸福度的小工具
  18. 加载css文件的几种方法,CSS 引入方式
  19. sql存储过程语法详解
  20. android版本过高导致下载软件后无法自动安装

热门文章

  1. iOS App的几种多视图介绍
  2. Android 5.0 SEAndroid下如何获得对一个内核节点的访问权限
  3. WINCE5.0+2443 camera中断不能进来的原因
  4. 实景三维系列4 | 为什么需要单体化
  5. 一张图了解华为手机背后的隐性福利,这些你不能再错过了!
  6. 用钉钉接收zabbix告警
  7. php拆分数字字符串方法
  8. Material DesignDrawerLayout的旋转箭头的实现方式。
  9. 网络基础---物理层
  10. 杭电 汉诺塔问题总结