Description

小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状,来看看小聪更爱谁,请完成RsubC类。RsubC类中包括Rectangle类和Circle类的数据成员,新增布尔类型的数据成员sign(sign等于0时,新面积等于Rectangle+Circle,sign等于1时,新面积等于Rectangle-Circle),新定义了求面积的成员函数area()。但是小聪没有为RsubC类写构造函数和成员函数,请帮助小聪完成RsubC类。

小强写的文件头和Shape类

#include<iostream>#define PI 3.14using 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;}

小聪写的Rectangle类class Rectangle:public Shape{public:Rectangle(int c,double w,double h);double getwidth();double getheight();double area();double price();protected:double height;double width;};Rectangle::Rectangle(int c,double w,double h):Shape(c){width=w;height=h;}double Rectangle::getwidth(){return width;}double Rectangle::getheight(){return height;}double Rectangle::area(){return height*width;}double Rectangle::price(){return height*width*color;}

小聪写的Circle类

class Circle:public Shape{public:Circle(int c,double r);double getradius();double area();double price();protected:double radius;};

Circle::Circle(int c,double r):Shape(c){radius=r;}double Circle::getradius(){return radius;}

double Circle::area(){return PI*radius*radius;}double Circle::price(){return PI*radius*radius*color;}

小聪的测试函数:

int main()

{

RsubC rc=RsubC(1,2,3,1,1);cout<<"RsubC area:"<<rc.area()<<endl;return 0;

}

提示:不用提交全部程序,只提交补充部分。

Input

Output

输出小聪测试的RsubC的面积。

Sample Output

RsubC area:2.86
#include<iostream>#define PI 3.14using 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(int c,double w,double h); double getwidth(); double getheight(); double area(); double price();protected: double height; double width;};Rectangle::Rectangle(int c,double w,double
h):Shape(c){ width=w; height=h;}double Rectangle::getwidth(){ return width;}double Rectangle::getheight(){ return height;}double Rectangle::area(){ return height*width;}double Rectangle::price(){ return height*width*color;} class Circle:public Shape{public:
Circle(int c,double r); double getradius(); double area(); double price();protected: double radius;}; Circle::Circle(int c,double r):Shape(c){ radius=r;}double Circle::getradius(){ return radius;} double Circle::area(){ return PI*radius*radius;}double Circle::price(){
return PI*radius*radius*color;}class RsubC:public Rectangle,public Circle{public: RsubC(int c,double w,double h,double r,bool s):Rectangle(c,w,h),Circle(c,r),sign(s){} float area();private: bool sign;};float RsubC::area(){ if(sign==1) return Rectangle::area()-Circle::area();
if(sign==1) return Rectangle::area()+Circle::area();}int main(){ RsubC rc=RsubC(1,2,3,1,1);cout<<"RsubC area:"<<rc.area()<<endl;return 0; }

												

[YTU]_2918( Shape系列-4)相关推荐

  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]_2917(Shape系列-3)

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

  7. [YTU]_2916(Shape系列-2)

    Description 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮.Rectangle类有整型的 ...

  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. Byte和byte[]数组
  3. java中System类、String Builder类简介
  4. oracle 存储过程 存储 blob,穿越oracle存储过程的Blob参数上传文件
  5. 菜鸟学Linux - bash的配置文件
  6. 笔记本连网线显示服务器拒绝连接怎么办,笔记本插上网线没反应怎么办【解决方法】...
  7. Android 获取当前日期算前一年、前一月、前一天Calendar
  8. python上传文件到oss_python实现上传文件到OSS
  9. android8 锁屏壁纸,小米8怎么设置锁屏壁纸?小米8锁屏壁纸三种设置教程
  10. 1.从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该年没有举办世界杯,则输出:没有举办世界杯。2. 读入一支球队的名字,输出该球队夺冠的年份列表。
  11. org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest
  12. 在2147483647的边缘疯狂试探
  13. 应用于音箱领域中的音频功放IC型号推荐
  14. python求上α分位点_什么是标准正态分布的上α分位点以及怎样求?
  15. oracle19c创建表空间,Oracle19c 创建表空间
  16. 搜狐邮件服务器地址加密方式,手把手教你如何用SMIME加密任意邮件
  17. RSS2.0简单介绍.
  18. mysql 死锁 navicat
  19. 150个常用的Linux命令汇总
  20. 最新互普威盾4.62 威盾4.5 4.33 互普威盾3.59 溢信IPGuard4.62 ip-guard4.5 IPguard4.33 IPGuard3.59 ip-guard4.51注册授权

热门文章

  1. [恢]hdu 2521
  2. Linux驱动开发环境配置(内核源码树构造)
  3. Windows Mobile Incoming Call View Custom
  4. [转]十天学习PHP之第一天(PHP)----基础知识
  5. 单元测试之道一:NUnit基础
  6. MySQL递归查询父节点或递归查询子节点-陈远波
  7. Linux基金会宣布开发区块链技术的新团队
  8. AlamofireJsonToObjects+EVReflection:一步解决JSON解析
  9. Selenium for C#的入门Demo
  10. matlab 学习之常用函数2