YTU 2918: Shape系列-4
2918: Shape系列-4
时间限制: 1 Sec 内存限制: 128 MB
提交: 276 解决: 232
题目描述

小强写的文件头和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;
}
输入
无
输出
输出小聪测试的RsubC的面积。
样例输出
RsubC area:2.86
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......
#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;
}
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 Shape
{
public:
RsubC(int c,double w,double h,double r,bool s);
double area();
private:
Rectangle rectangle;
Circle circle;
bool sign;
};
RsubC::RsubC(int c,double w,double h,double r,bool s):Shape(c),rectangle(c,w,h),circle(c,r),sign(s) {}
double RsubC::area()
{
if(sign==0)
return rectangle.area()+circle.area();
else
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系列-5
2919: Shape系列-5 时间限制: 1 Sec 内存限制: 128 MB 提交: 251 解决: 199 题目描述 JC和Kitty听说小亮和小华有了Rectangle和Circle并用R ...
- 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标签的基本使用情 ...
随机推荐
- zoj 2932 The Seven Percent Solution
The Seven Percent Solution Time Limit: 2 Seconds Memory Limit: 65536 KB Uniform Resource Identi ...
- Go 在游戏行业中的工程实践
在今年 1 月由七牛云主办的 ECUG Con 十周年盛会上,真有趣技术总监陈明达带来了题为< Go 在游戏行业中的工程实践>的精彩分享,深入讲解了 Go 的工程经验,错误和异常处理,in ...
- [luoguP1772] [ZJOI2006]物流运输(DP + spfa)
传送门 预处理cost[i][j]表示从第i天到第j天起点到终点的最短距离 f[i]表示前i天到从起点到终点的最短距离 f[0] = -K f[i] = min(f[i], f[j - 1] + co ...
- bzoj 2326 矩阵乘法
[HNOI2011]数学作业 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2415 Solved: 1413[Submit][Status][Di ...
- Gerrit实现代码审计(code review)
1.Gerrit是个啥? 实现代码审计,比git(gitlab.github)多了代码审计的功能. 2.两类角色 角色1:我是代码编写者,只能写代码和提交给审计者代码,不能直接把代码合并到线上发布 角 ...
- 手机没Root?你照样可以渗透路由器
和Metasploit差不多,RouterSploit是一个强大的漏洞利用框架,用于快速识别和利用路由器中的普通漏洞,它还有个亮点,就是可以在绝大多数安卓设备上运行. 如果你想在电脑上运行,可以阅读这 ...
- 积跬步,聚小流------ps有用小技巧,改变png图标颜色
* 实现效果: 原图: 改动后: * 实现目的: 满足为实现不同界面色彩搭配改动png图标的颜色 * 实现方法: 1.打开Photoshop工具,导入须要进行改动的png图标: 2.对导入的图 ...
- 手把手教你_怎么找android应用的包名和启动activity
自己主动化測试中常常遇到这个问题,关于这个题目,方法众多,咱的目的是找个比較简单靠谱的: 方法一: 先进入cmd窗体,adb shell 后: cd /data/data ls 能够看到包名了吧,缺点 ...
- PRD编写Axure内直接编辑
流程&页面&交互&逻辑 功能点: 1,选项类 设置默认值. 2,输入文本类 设置最多最少字符数. 3,功能按钮,如提交.发布. 判断敏感词,如果有,则点击发布的时候,悬浮提醒“ ...
- 导入项目 R.java没有
网上一搜,各种 Android tools-fix your porject或者Clean ...不好使 其实可能是由于XML布局文件有错误导致,修改掉这些错误就可以了..