[YTU]_2918( Shape系列-4)
来源:互联网 发布:个人网站博客系统php 编辑:程序博客网 时间:2024/06/07 20:24
Description
小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状,来看看小聪更爱谁,请完成RsubC类。RsubC类中包括Rectangle类和Circle类的数据成员,新增布尔类型的数据成员sign(sign等于0时,新面积等于Rectangle+Circle,sign等于1时,新面积等于Rectangle-Circle),新定义了求面积的成员函数area()。但是小聪没有为RsubC类写构造函数和成员函数,请帮助小聪完成RsubC类。小强写的文件头和Shape类
#include<iostream> #define PI 3.14 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; }
小聪写的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)
- YTU 2918: Shape系列-4
- YTU 2915: Shape系列-1
- YTU 2916: Shape系列-2
- YTU 2917: Shape系列-3
- YTU 2918: Shape系列-5
- YTU 2920: Shape系列-7
- YTU 2922: Shape系列-8
- [YTU]_2915(Shape系列-1)
- [YTU]_2916(Shape系列-2)
- [YTU]_2917(Shape系列-3)
- [YTU]_2919( Shape系列-5)
- [YTU]_2920( Shape系列-6)
- [YTU]_2921( Shape系列-7)
- [YTU]_2922(Shape系列-8)
- OJ嘻唰唰 Shape系列-4
- Android系列: 自定义图形shape
- OJ嘻唰唰Shape系列-6
- 常用linux日志查询命令
- mybatis-分步查询方式传递多列的值-16
- bzoj2152 聪聪与可可 点分治
- Android隐藏软键盘
- 导航区不变内容区变
- [YTU]_2918( Shape系列-4)
- Entrance Pupil AND Exit Pupil
- 理解TIME_WAIT
- 听说你精通TCP,来问你几个问题考考你是不是真的精通
- druid监控配置及sql注入防火墙配置
- 字符串哈希
- WEB服务器与应用服务器的区别
- arduino等开源平台
- [leetCode刷题笔记]606. Construct String from Binary Tree