[YTU]_2916(Shape系列-2)
Description
小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮。Rectangle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员width和height,求面积的成员函数area()。但是小聪没有为Rectangle类写构造函数和成员函数,请帮助小聪完成Rectangle类。
#include<iostream>
using namespace std;
{
Shape::Shape(int c)
{
int Shape::getcolor()
{
return color;
double Shape::area()
{
return 10000;
}
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)相关推荐
- YTU 2917: Shape系列-3
2917: Shape系列-3 时间限制: 1 Sec 内存限制: 128 MB 提交: 372 解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...
- [YTU]_2920( Shape系列-6)
Description Shape系列终于快完成了,小聪可以歇一下了.但是这个时候JC和Kitty把自己的矩形和圆形做好,想给小聪比试一下,小聪也不示弱,拿出来自己的做出的三角形和他们一分高下.他们的 ...
- [YTU]_2922(Shape系列-8)
Description 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小聪自力更生创建了Point类,但是他没有写Point类.继承Point类的Circle类.继承Circ ...
- [YTU]_2921( Shape系列-7)
Description 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函数的问题,请大家根据题意,帮助小强完成改动后的Shape类. 小强写的各种类 class Rectang ...
- [YTU]_2919( Shape系列-5)
Description JC和Kitty听说小亮和小华有了Rectangle和Circle并用RsubC类比较了大小,于是想借小亮和小华的Rectangle和Circle来仿制自己的形状,于是JC和K ...
- [YTU]_2918( Shape系列-4)
Description 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状,来看看小聪更爱谁,请完成RsubC类.RsubC类中包括Rectangle类和Circle类的数据成员 ...
- [YTU]_2917(Shape系列-3)
送给小亮的Rectangle类已完成,送给小华Circle类还没有完成.Circle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员radiu ...
- [YTU]_2915(Shape系列-1)
Description 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有整型的数据成员color,求面积的成员函数area().小强针对不知道千奇百怪的Shape如何求面积,于 ...
- Android2D绘图一
View 只是把Graphic 资源(images,shapes,colors,pre-defined animation等等这些Android已经实现的一些画图操作)放入View体系,由系统 来将这 ...
最新文章
- 快来支招~程序员怎么哄女朋友? | 每日趣闻
- 怎么判断模式窗体打开的窗体名_QtitanRibbon是什么?该怎么用?
- brew 安装mysql5.6_mac使用brew安装mysql的坑
- [转]OpenGL库介绍
- css如何插入动态图,css动态图(作业)
- maven构建java web项目(idea开发)
- RabbitMQ学习之spring-amqp的重要类的认识
- 网易游戏开发工程师笔试题
- 开篇 | 揭秘 Flink 1.9 新架构,Blink Planner 你会用了吗?
- 【Xamarin挖墙脚系列:mac 终端 常用命令+Mac OS X的快捷键+beamoff 】
- 微信小程序 input ,阻止冒泡事件,catchtap的使用
- 单片机AD采样的几种算法
- STM32单片机实现二维码显示
- 一个正整数到 Excel 编号之间的转换
- 放弃数学专业跳槽高薪行业,如今他却后悔了
- 洛克希德·马丁定义的“杀伤链”
- 盘点那些真正能提升工作幸福度的小工具
- 加载css文件的几种方法,CSS 引入方式
- sql存储过程语法详解
- android版本过高导致下载软件后无法自动安装