YTU 2922: Shape系列-8
2922: Shape系列-8
时间限制: 1 Sec 内存限制: 128 MB
提交: 172 解决: 99
题目描述
,但是小聪自力更生创建了Point类,但是他没有写Point类、继承Point类的Circle类、继承Circle类的Cylinder类这3个类的构造函数,请你帮忙补充这几个类未完成的函数。#define PI 3.14159
class Point
{
public:
Point(float=0,float=0);
void setPoint(float,float);
float getX()const ;
float getY()const ;
friend ostream & operator<<(ostream &,const Point &);
protected:
float x,y;
};
class Circle:public Point
{
public:
Circle(float x=0,float y=0,float r=0);
void setRadius(float);
float getRadius() const;
float area () const;
friend ostream &operator<<(ostream &,const Circle &);
protected:
float radius;
};
class Cylinder:public Circle
{
public:
Cylinder (float x=0,float y=0,float r=0,float h=0);
void setHeight(float);
float getHeight() const;
float area() const;
float volume() const;
friend ostream& operator<<(ostream&,const Cylinder&);
protected:
float height;
};
{
Cylinder cy1(3.5,6.4,5.2,10);
cy1.setHeight(15);
cy1.setRadius(7.5);
cy1.setPoint(5,5);
cout<<"new cylinder:\n"<<cy1;
Point &pRef=cy1;
cout<<"pRef as a point:"<<pRef;
Circle &cRef=cy1;
cout<<"cRef as a Circle:"<<cRef;
return 0;
}
输入
无
输出
输出小聪测试的各个数据
样例输出
new cylinder:
Center=[5,5], r=7.5, h=15
area=1060.29, volume=2650.72
pRef as a point:[5,5]
cRef as a Circle:Center=[5,5], r=7.5, area=176.714
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......
#include <iostream>
using namespace std;
#define PI 3.14159
class Point
{
public:
Point(float=0,float=0);
void setPoint(float,float);
float getX()const ;
float getY()const ;
friend ostream & operator<<(ostream &,const Point &);
protected:
float x,y;
};
class Circle:public Point
{
public:
Circle(float x=0,float y=0,float r=0);
void setRadius(float);
float getRadius() const;
float area () const;
friend ostream &operator<<(ostream &,const Circle &);
protected:
float radius;
};
class Cylinder:public Circle
{
public:
Cylinder (float x=0,float y=0,float r=0,float h=0);
void setHeight(float);
float getHeight() const;
float area() const;
float volume() const;
friend ostream& operator<<(ostream&,const Cylinder&);
protected:
float height;
};
Cylinder::Cylinder(float x,float y,float r,float h)
{
height=h;
radius=r;
this->y=y;
this->x=x;
}
Circle::Circle(float x,float y,float r) {}
void Cylinder::setHeight(float a)
{
height=a;
}
Point::Point(float a,float b) {}
void Circle::setRadius(float a)
{
radius=a;
}
void Point::setPoint(float a,float b)
{
x=a;
y=b;
}
ostream & operator<<(ostream &a,const Point &b)
{
a<<"["<<b.x<<","<<b.y<<"]"<<endl;
return a;
}
ostream &operator<<(ostream &a,const Circle &b)
{
a<<"Center=["<<b.x<<","<<b.y<<"], r="<<b.radius<<", area="<<b.radius*b.radius*PI<<endl;
return a;
}
ostream& operator<<(ostream &a,const Cylinder &b)
{
a<<"Center=["<<b.x<<","<<b.y<<"], r="<<b.radius<<", h="<<b.height<<endl;
a<<"area="<<2*PI*b.radius*b.radius+2*PI*b.radius*b.height<<", volume="<<b.radius*b.radius*PI*b.height<<endl;
return a;
}
int main()
{
Cylinder cy1(3.5,6.4,5.2,10);
cy1.setHeight(15);
cy1.setRadius(7.5);
cy1.setPoint(5,5);
cout<<"new cylinder:\n"<<cy1;
Point &pRef=cy1;
cout<<"pRef as a point:"<<pRef;
Circle &cRef=cy1;
cout<<"cRef as a Circle:"<<cRef;
return 0;
}
YTU 2922: Shape系列-8的更多相关文章
- YTU 2920: Shape系列-7
2921: Shape系列-7 时间限制: 1 Sec 内存限制: 128 MB 提交: 156 解决: 129 题目描述 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函 ...
- YTU 2918: Shape系列-4
2918: Shape系列-4 时间限制: 1 Sec 内存限制: 128 MB 提交: 276 解决: 232 题目描述 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状 ...
- YTU 2918: Shape系列-5
2919: Shape系列-5 时间限制: 1 Sec 内存限制: 128 MB 提交: 251 解决: 199 题目描述 JC和Kitty听说小亮和小华有了Rectangle和Circle并用R ...
- 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标签的基本使用情 ...
随机推荐
- 数组和String几种方法的需要注意的地方
array的方法总结 会更改原来的的数组 push.unshift方法,返回length.增加值得就返回length,其他返回该元素 pop,shift返回该元素 reverse返回该元素 splic ...
- STM32F407 STLINK 在线调试 个人笔记
配置的部分请看本博客STM32分类下的环境配置篇目 开始调试 一些按键 查看寄存器 查看变量值 选中变量,右键,add to watch
- Ext修改Confirm弹框按钮的默认值
- 如何使用werkzeug创建WSGI APP
注意 : 1.定义__call__的意义 class App(): def __init__(self): pass def method(self): pass app=App() app() #错 ...
- POJ3321Apple Tree【dfs 树状数组】
题目大意:一棵树(不一定是二叉树!!),树的节点上本来都有一个苹果,要求完成以下操作: 1.指定某个节点,如果这个节点原本有苹果则拿去,如果没有苹果则填上一个苹果 2.询问某个节点以及其子树一共有多少 ...
- PHP字符串的替换(preg_replace)
/* 正则表达式 preg_replace() */ $str = array( "如果没有一些http://www.abc.com特殊的<b>替换</b>需5求( ...
- redis安装【三】
目录介绍: 0.Windows下下载安装包: 下载地址: https://redis.io/ 1.上传到linux服务器 将文件上传到192.168.2.128主机的usr/local目录下: C:\ ...
- JOI 2019 Final合集
JOI 2019 Final 合集 #3010. 「JOI 2019 Final」勇者比太郎 其实如果读懂题了就是水题了 题目就是让你求满足条件的\(JOI\),使得\(O\)在\(J\)同行的 ...
- The Doors--poj1556(最短路+判断点与线段的关系)
http://poj.org/problem?id=1556 题目大意:从(0,5)走到(10,5)走的最短距离是多少 中间有最多18个隔着的墙 每个墙都有两个门 你只能从门通过 我的思路是 只 ...
- P2835 刻录光盘
洛谷—— P2835 刻录光盘 题目描述 在JSOI2005夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘给大家,以便大家回去后继续学习.组委会觉得这个主意不错!可是组委会 ...