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标签的基本使用情 ...
随机推荐
- angularjs自己总结
1.模块 自定的directive和controller需要在同一个model下,或者另外的model depModules他了. ng-app要等于model的名字,所有的directive要在下面 ...
- xtu read problem training B - Tour
B - Tour Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descriptio ...
- Tao Tao要吃鸡(01背包)
题目描述 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了,和绝地求生一样,游戏人物本身可以携带一定重量m的物品,装备背包之后可以多携带h(h为0代表没有装备背包)重量的东 ...
- php 面向对象 (类 对象)
//面向对象//什么是面向对象//面向过程//什么是对象?//一切皆是对象//类//由对象抽象化//造类//class Ren//{ //构造方法 - - 写不写都存在//类的初始化方法 //构造方法 ...
- 【java基础 3】树形结构数据呈现的递归算法实现
一.基本概况 在我的项目中,常常会用到树形结构的数据,最为明显的就是左边菜单栏,类似于window folder一样的东西. 而我之前一直是借助前端封装好的ZTree等工具实现展示,而后台则通常使用递 ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- CSU 1307 最短路+二分
题目大意: 帮忙找到一条a到b的最短路,前提是要保证路上经过的站点的最大距离尽可能短 这道题居然要用到二分...完全没去想过,现在想想求最大距离的最小值确实是... 这里不断二分出值代入spfa()或 ...
- Lucene的例子
lucene爬数据库中的数据无非也是查询数据.所有我们用lucene搜索数据主要有下面几个步骤:(代码紧供参考) 一 , 从数据库中查数据 ====爬数据 ------------- ...
- vs code 使用心得
Jetbrains 家族的软件适合java,python开发,但是对与rust,shell等的开发,则显得有些臃肿,需要一款轻快的编辑器,经过挑选,在sublime3 与 vs code 中选则了vs ...
- hdu 2736 Average distance
传送门 Average distance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...