YTU 2918: Shape系列-5
2919: Shape系列-5
时间限制: 1 Sec 内存限制: 128 MB
提交: 251 解决: 199
题目描述
//小强写的文件头和各种类
#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的更多相关文章
- YTU 2918: Shape系列-4
2918: Shape系列-4 时间限制: 1 Sec 内存限制: 128 MB 提交: 276 解决: 232 题目描述 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状 ...
- YTU 2922: Shape系列-8
2922: Shape系列-8 时间限制: 1 Sec 内存限制: 128 MB 提交: 172 解决: 99 题目描述 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小 ...
- YTU 2920: Shape系列-7
2921: Shape系列-7 时间限制: 1 Sec 内存限制: 128 MB 提交: 156 解决: 129 题目描述 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函 ...
- YTU 2917: Shape系列-3
2917: Shape系列-3 时间限制: 1 Sec 内存限制: 128 MB 提交: 372 解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...
- YTU 2916: Shape系列-2
2916: Shape系列-2 时间限制: 1 Sec 内存限制: 128 MB 提交: 268 解决: 242 题目描述 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小 ...
- YTU 2915: Shape系列-1
2915: Shape系列-1 时间限制: 1 Sec 内存限制: 128 MB 提交: 283 解决: 221 题目描述 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有 ...
- WPF 2D图形 Shape入门(一)--Shape
本文是篇WPF Shape的入门文章 Shape 首先看看shape的继承链关系: 一个Shape具有哪些重要属性: 属性 说明 DefiningGeometry 默认的几何形状 RenderedGe ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型
<zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...
- Android系列:res之shape制作
大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...
随机推荐
- Linux 下Python2.7解决list打印中文字符问题
在写一个爬取智联招聘数据的爬虫中,将所需内容匹配到后打印出现了utf-8字符,并没有出现中文字符. 例如: >>>listnine = ['梨', '橘子', '苹果', '香蕉'] ...
- ACboy needs your help(分组背包)
ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he ...
- Vim增强工具设置
Vim增强工具设置操作准备:vim ~/.vimrc11. 缩进 & 制表符使 Vim 在创建新行的时候使用与上一行同样的缩进: set autoindent 2. 设置文件里的制表符 (TA ...
- Attribute "not-null" must be declared for element type "property"解决办法
Attribute "not-null" must be declared for element type "property"解决办法 在hiberante ...
- Java调用K3Cloud的密码加密算法实现登录密码检验
背景: 最近要开始做K3Cloud移动,BOS平台的移动单据收费,就想单独做移动模块,搭建环境:后台SSH2,前端Android.在手机端登录时通过Ajax方式传递用户名和密码到后台校验,后台在去K3 ...
- IntelliJ IDEA平台下JNI编程—HelloWorld篇
转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001/article/details/53906237] JNI(Java Native I ...
- 如何通过AS3加载外部SWF文件,调用外部文件文档类的方法?
一个Flash中通过AS3代码的Loader对象加载另一个SWF文件,并访问其中的文档类中的方法. 简单示例: 主文件:Main.fla, Main.as 被调用的文件:called.swf, Cal ...
- BZOJ 4894 有向图 外向生成树个数
4894: 天赋 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 191 Solved: 150[Submit][Status][Discuss] D ...
- 2015轻院校赛 B 迷宫 (bfs)
http://acm.zznu.edu.cn/problem.php?id=1967 这套题的有毒 我交了好多遍才对 坑:机关要按照顺序走 并且在走这个机关之前不能走这个机关 但是能穿过这个机关 ...
- iOS: 解决Asset Catalog Compile Error - TDDIstiller instance can only be distilled only one time的错误
执行命令:rm -rf /Users/<用户名>/Library/Developer/Xcode/DerivedData 然后重新编译项目即可.