2919: Shape系列-5

时间限制: 1 Sec  内存限制: 128 MB

提交: 251  解决: 199

题目描述

JC和Kitty听说小亮和小华有了Rectangle和Circle并用RsubC类比较了大小,于是想借小亮和小华的Rectangle和Circle来仿制自己的形状,于是JC和Kitty完成了自己的rectangle类和circle类,他们两个也要比较一下形状大小。但是JC和Kitty没有为RsubC1类(其中的布尔类型sign等于0时,新面积等于Rectangle+Circle,sign等于1时,新面积等于Rectangle-Circle)写构造函数与area面积函数,请帮助JC和Kitty完成RsubC1类。

//小强写的文件头和各种类

#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; 

}

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

输入

输出

输出JC和Katy测试的RsubC类的面积。

样例输出

rc1 area=2.86
rc2 area=14.56

im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......

#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==0)
return rectangle.area()+circle.area();
else
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 2918: Shape系列-5的更多相关文章

  1. YTU 2918: Shape系列-4

    2918: Shape系列-4 时间限制: 1 Sec  内存限制: 128 MB 提交: 276  解决: 232 题目描述 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状 ...

  2. YTU 2922: Shape系列-8

    2922: Shape系列-8 时间限制: 1 Sec  内存限制: 128 MB 提交: 172  解决: 99 题目描述 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小 ...

  3. YTU 2920: Shape系列-7

    2921: Shape系列-7 时间限制: 1 Sec  内存限制: 128 MB 提交: 156  解决: 129 题目描述 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函 ...

  4. YTU 2917: Shape系列-3

    2917: Shape系列-3 时间限制: 1 Sec  内存限制: 128 MB 提交: 372  解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...

  5. YTU 2916: Shape系列-2

    2916: Shape系列-2 时间限制: 1 Sec  内存限制: 128 MB 提交: 268  解决: 242 题目描述 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小 ...

  6. YTU 2915: Shape系列-1

    2915: Shape系列-1 时间限制: 1 Sec  内存限制: 128 MB 提交: 283  解决: 221 题目描述 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有 ...

  7. WPF 2D图形 Shape入门(一)--Shape

    本文是篇WPF Shape的入门文章 Shape 首先看看shape的继承链关系: 一个Shape具有哪些重要属性: 属性 说明 DefiningGeometry 默认的几何形状 RenderedGe ...

  8. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...

  9. Android系列:res之shape制作

    大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...

随机推荐

  1. window查看哪些端口被占用命令

    管理员方式运行cmd netstat -n

  2. jenkins 提示No emails were triggered

    发送邮件 Jenkins->系统管理->系统设置,在“邮件通知”里设置smtp服务器地址,以及发送者邮箱地址,在具体的任务构建完成以后,可以设置发送邮件,在某一个任务的"Add ...

  3. Halloween Costumes(区间DP)

    Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning t ...

  4. ASP.NET MVC WebAPI请求

    基础: 首先,先创建一个“ASP.NET 空Web应用程序” : 然后添加对 “System.Web.Http” 和 “System.Web.Http.WebHost” 的引用: 再添加对“Syste ...

  5. Codevs 3409 搬礼物

    时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze   题目描述 Description 小浣熊松松特别喜欢交朋友,今年松松生日,就有N个朋友给他送礼物.可是要把这些礼 ...

  6. spring mvc dispatcherServlet

    1. 在web.xml中配置servlet对相应的url请求进行处理 <servlet> <servlet-name>springDispatcher</servlet- ...

  7. 有向图欧拉回路个数 BEST定理

    有向图欧拉回路个数 BZOJ 3659 但是没有这道题了  直接贴一个别人的板子吧 欧拉回路:存在一条路径经过所有的边刚好1次 有向图欧拉回路存在充要条件:①图连通:②对于所有点都满足出度=入度 BE ...

  8. [Bzoj1296][Scoi2009] 粉刷匠 [DP + 分组背包]

    1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2184  Solved: 1259[Submit][Statu ...

  9. 初学总结--------Java修饰符与修饰关键字(且叫修饰关键字)

    Java中有类,有成员变量,有成员方法,有局部变量.他们分别能用什么来修饰? 目前学习到的类,有普通类和内部类. 一.修饰普通类: 1.public  每个文件中只有一个类能被public修饰,表示可 ...

  10. 洛谷 P3811 【模板】乘法逆元

    P3811 [模板]乘法逆元 题目背景 这是一道模板题 题目描述 给定n,p求1~n中所有整数在模p意义下的乘法逆元. 输入输出格式 输入格式: 一行n,p 输出格式: n行,第i行表示i在模p意义下 ...