[YTU]_2917(Shape系列-3)
小强写的Shape类:
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()
{
Circle cc=Circle(3,1);
cout<<"Circle color:"<<cc.getcolor()<<endl
<< "Circle radius:"<<cc.getradius()<<endl
<< "Circle area:"<<cc.area()<<endl
<< "Circle price:"<<cc.price()<<endl;
return 0;
}
Input
无
Output
输出小聪测试的Circle类的各个数据。
Sample Output
Circle color:3 Circle radius:1 Circle area:3.14 Circle price:9.42
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;
}
#include <iostream>
#define PI 3.14
using namespace std;
class Circle:public Shape
{
public:Circle(int c,float r):Shape(c),radius(r){}int getradius();float area();float price();
private:int radius;
};
int Circle::getradius()
{return radius;}
float Circle::area()
{return radius*radius*PI;}
float Circle::price()
{return color*PI;}
int main()
{
Circle cc=Circle(3,1);
cout<<"Circle color:"<<cc.getcolor()<<endl
<<"Circle radius:"<<cc.getradius()<<endl
<<"Circle area:"<<cc.area()<<endl
<<"Circle price:"<<cc.price()<<endl;
return 0;
}
[YTU]_2917(Shape系列-3)相关推荐
- 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]_2916(Shape系列-2)
Description 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮.Rectangle类有整型的 ...
- [YTU]_2915(Shape系列-1)
Description 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有整型的数据成员color,求面积的成员函数area().小强针对不知道千奇百怪的Shape如何求面积,于 ...
- Android2D绘图一
View 只是把Graphic 资源(images,shapes,colors,pre-defined animation等等这些Android已经实现的一些画图操作)放入View体系,由系统 来将这 ...
最新文章
- 正则的实例用法,删除包含某些字符的字符串
- R单变量可视化(Histograms、 Index Plots、Time-Series Plots、Pie Charts)
- tomcat升级_「shell脚本」懒人运维之自动升级tomcat应用(war包)
- 2017西安交大ACM小学期 有趣异或[Trie树]
- Linux NTP服务配置 for Oracle RAC
- Leetcode 23.移除元素
- iOS in-app purchase详解
- [转载] vscode python导入模块
- (JS基础)操作表单
- 非线性系统稳定性理论分析、设计方法
- 专利交底书怎么写 -
- 视频转换器怎么将视频转成GIF动画
- C语言:逆转线性链表
- Superfetch与Readyboost完全解析
- Docker可视化工具——Portainer全解
- MediaCodec编码后视频时长不正确的问题
- 华为鸿蒙2.0来了,挑战谷歌安卓APP成关键?
- gitlab报错502
- 只要5分钟!学会自己打造多系统合集的DVD安装光盘
- 最优化——阻尼牛顿法