[YTU]_2919( Shape系列-5)
Description
//小强写的文件头和各种类
#include<iostream>
using namespace std;
#define pi 3.14
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 1000;
}
class Rectangle:public Shape
{
public:
Rectangle();
Rectangle(int c, double w,double h);
double getwidth();
double getheight();
double area();
double price();
protected:
double width,height;
};
Rectangle::Rectangle()
{
width=10;height=5;
}
Rectangle::Rectangle(int c, double w,double h):Shape(c)
{
width=w;
height=h;
}
double Rectangle::getwidth()
{
return width;
}
double Rectangle::area()
{
return width*height;
}
double Rectangle::getheight()
{
return height;
}
double Rectangle::price()
{
return color*width*height;
}
class Circle:public Shape
{
public:
Circle();
Circle(int c,double r);
double getradius()
{
return radius;
}
double area();
protected:
double radius;
};
Circle::Circle()
{
radius=10;
}
Circle::Circle(int c,double r):Shape(c)
{
radius=r;
}
double Circle::area()
{
return radius*radius*pi;
}
// RsubC1类
class RsubC1:public Shape
{
public:
RsubC1(int c,double w,double h,double r,bool s);
double area();
private:
Rectangle rectangle;
Circle circle;
bool sign;
};
//JC和Katy的测试函数:
int main()
{
RsubC1 rc1=RsubC1(3,2,3,1,1);
RsubC1 rc2=RsubC1(1,2,1,2,0);
cout<<"rc1 area="<<rc1.area()<<endl;
cout<<"rc2 area="<<rc2.area()<<endl;
return 0;
}
Input
无
Output
输出JC和Katy测试的RsubC类的面积。
Sample Output
rc1 area=2.86rc2 area=14.56
#include<iostream>
using namespace std;
#define pi 3.14
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 1000;
}
class Rectangle:public Shape
{
public:Rectangle();Rectangle(int c, double w,double h);double getwidth();double getheight();double area();double price();
protected:double width,height;
};
Rectangle::Rectangle()
{width=10;height=5;
}
Rectangle::Rectangle(int c, double w,double h):Shape(c)
{width=w;height=h;
}
double Rectangle::getwidth()
{return width;
}double Rectangle::area()
{return width*height;
}
double Rectangle::getheight()
{return height;
}double Rectangle::price()
{return color*width*height;
}
class Circle:public Shape
{
public:Circle();Circle(int c,double r);double getradius(){return radius;}double area();
protected:double radius;
};
Circle::Circle()
{radius=10;
}
Circle::Circle(int c,double r):Shape(c)
{radius=r;
}
double Circle::area()
{return radius*radius*pi;
}class RsubC1:public Shape
{
public:RsubC1(int c,double w,double h,double r,bool s);double area();
private:Rectangle rectangle;Circle circle;bool sign;
};RsubC1::RsubC1(int c,double w,double h,double r,bool s):Shape(c),rectangle(c,w,h),circle(c,r),sign(s){}
double RsubC1::area()
{if(sign==1)return rectangle.area()-circle.area();if(sign==0)return rectangle.area()+circle.area();
}
int main()
{ RsubC1 rc1=RsubC1(3,2,3,1,1);RsubC1 rc2=RsubC1(1,2,1,2,0);cout<<"rc1 area="<<rc1.area()<<endl; cout<<"rc2 area="<<rc2.area()<<endl; return 0;
}
[YTU]_2919( Shape系列-5)相关推荐
- 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]_2918( Shape系列-4)
Description 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状,来看看小聪更爱谁,请完成RsubC类.RsubC类中包括Rectangle类和Circle类的数据成员 ...
- [YTU]_2917(Shape系列-3)
送给小亮的Rectangle类已完成,送给小华Circle类还没有完成.Circle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员radiu ...
- [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体系,由系统 来将这 ...
最新文章
- Pytorch中的广播机制
- 来自Mozilla的CSS书写规范建议
- Tableau可视化分析实战系列Tableau基础概念全解析 (一)-数据结构及字段
- GraphPad Prism 9.2 Mac 2021最新安装使用教程
- 连遭主流社交应用抛弃,是时候宣判黑莓系统死刑了
- bzoj1997 [HNOI2010]平面图判定Plana
- 策略模式、上下文与内部类的思考
- vim 寄存器中的 ^@,^M,^J
- jquery mobile 从一个html的page跳转到另一个html的page
- 简体中文 Windows 7 Beta 体验(图)
- python3汉字转unicode_Python3 编码问题: 怎么将Unicode转中文,以及GBK乱码ÖйúÉÙÊýÃñ×åÌØÉ«´åÕ¯...
- Bochs 调试命令
- 摩托罗拉投资Android社交游戏拓荒商Moblyng
- Oracle的分析函数over()
- 谷歌云盘和百度云盘文件转存
- python实现等量随机分组
- Proxifier实现指定进程代理IP 雷电模拟器为例
- 管理系统页面布局 html,25 个精美的后台管理界面模板和布局
- pytorch中的pad_sequence、pack_padded_sequence和pad_packed_sequence函数
- 深入浅出计算机组成原理:冒险和预测(一)-hazard是“危”也是“机(第22讲)...
热门文章
- AS3.0 正则表达式规则
- Windows Mobile Incoming Call View Custom
- 19日零时起降低成品油价格 燃油税元旦起开征
- 理解ROS话题---ROS学习第5篇
- xp宿主机和VMware下Ubuntu12.04共享文件夹
- python 下载网页文件_『如何用python把网页上的文本内容保存下来』python爬取网页内容教程...
- WCF与ASP.NET Core性能比较
- echart地图配置
- nslookup命令详解【转】
- 【HDU】4405 Aeroplane chess