2922: Shape系列-8

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

提交: 172  解决: 99

题目描述

小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小聪自力更生创建了Point类,但是他没有写Point类、继承Point类的Circle类、继承Circle类的Cylinder类这3个类的构造函数,请你帮忙补充这几个类未完成的函数。
小聪写的各种类
#include <iostream.h>

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

};
//小聪用于测试的函数
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;

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

输入

输出

输出小聪测试的各个数据

样例输出

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的更多相关文章

  1. YTU 2920: Shape系列-7

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

  2. YTU 2918: Shape系列-4

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

  3. YTU 2918: Shape系列-5

    2919: Shape系列-5 时间限制: 1 Sec  内存限制: 128 MB 提交: 251  解决: 199 题目描述 JC和Kitty听说小亮和小华有了Rectangle和Circle并用R ...

  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. 关于构造函数什么值传递给他的实例,只有this和prototype

    var a= function (){var bb = 12; this.aa ="xxx"}; a.aa="www"; a.prototype.cc=&quo ...

  2. httpclient调用webservice接口的方法实例

    这几天在写webservice接口,其他的调用方式要生成客户端代码,比较麻烦,不够灵活,今天学习了一下httpclient调用ws的方式,感觉很实用,话不多说,上代码 http://testhcm.y ...

  3. Ubuntu安装sublime Text 3并配置可以输入中文

    使用Ubuntu系统后,想找一个顺手的编辑器,sublime作为我的首选编辑器,在安装和配置可输入中文时遇到各种个样的问题,总结一些: 1:问题: 我的系统是Ubuntu 18.04 LTS,尝试多次 ...

  4. Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理

    前言 java开发中经常遇到对图片的处理,JDK中也提供了对应的工具类,不过处理起来很麻烦,Thumbnailator是一个优秀的图片处理的开源Java类库,处理效果远比Java API的好,从API ...

  5. linux 常见名词及命令(二)

    pwd 用于显示当前的工作目录. cd 用于切换工作路径 cd - 切换到上一次的目录 cd ~ 切换到家目录 cd ~username 切换到其他用户的家目录 cd .. 切换到上级目录 ls 用于 ...

  6. Dividing--hdu1059(动态规划)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  7. mysql登录退出命令

    1. MySQL登录与退出登录Mysql:“输入mysql -u帐号 -p密码 这是登陆mysql退出:mysql > exit;以下是实例参考下: 登录Mysql:“输入mysql -uroo ...

  8. 系统性能不够原因可能是cpu不够,内存不够等等

    1.Linux系统可以通过top命令查看系统的CPU.内存.运行时间.交换分区.执行的线程等信息. 通过top命令可以有效的发现系统的缺陷出在哪里.是内存不够.CPU处理能力不够.IO读写过高. 2. ...

  9. Office EXCEL 的绝对引用和相对引用如何理解

    比如C1 = A1+B1,则我把C1的单元格往下拖拉的时候,C2会自动等于A2+B2,C3会自动等于A3+B3,而如果让G1 = $E$1+$F$1,则把G1单元格往下拖拉的时候,G2G3单元格都不会 ...

  10. Codeforces Round #135 (Div. 2)---A. k-String

    k-String time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...