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. linux进程按启动时间排序命令

    show me the code... ps aux --sort=start_time|grep Full|grep -v grep

  2. Charm Bracelet(01背包)

    Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...

  3. FZU-2148-Moon Game,,几何计算~~

    Problem 2148 Moon Game Time Limit: 1000 mSec Memory Limit : 32768 KB  Problem Description Fat brothe ...

  4. bzoj 1432 [ZJOI2009]Function 思想

    [bzoj1432][ZJOI2009]Function Description Input 一行两个整数n; k. Output 一行一个整数,表示n 个函数第k 层最少能由多少段组成. Sampl ...

  5. 我是一个线程 - IBM刘欣

    来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...

  6. 道路游戏(洛谷 P1070)

    题目描述 小新正在玩一个简单的电脑游戏. 游戏中有一条环形马路,马路上有 n 个机器人工厂,两个相邻机器人工厂之间由一小段马路连接.小新以某个机器人工厂为起点,按顺时针顺序依次将这 n 个机器人工厂编 ...

  7. [Vijos] 天才的记忆

    背景 神仙飞啊飞 描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松回答出这个问题,便可以 ...

  8. JavaScript 将行结构数据转化为树结构数据源(高效转化方案)

    js接收到后台的数据如下 /// 部门信息 var departRows = [{ parentDepartId: 'root', departId: 'DC', departName: '集团' } ...

  9. c++ 高性能日志库(muduo_AsyncLogging)

    c++ 高性能日志库(muduo_AsyncLogging) 实现一个高效的网络日志库要解决那些问题? 首先明确一下问题的模型,这是一个典型的多生产者 单消费者问题,对于前端的日志库使用者来说,应该做 ...

  10. PAT (Advanced Level) 1039. Course List for Student (25)

    map会超时,二分吧... #include<iostream> #include<cstring> #include<cmath> #include<alg ...