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. JS获取粘贴内容

    http://classjs.com/2013/03/05/js%E8%8E%B7%E5%8F%96%E7%B2%98%E8%B4%B4%E5%86%85%E5%AE%B9/ 思路:在编辑环境中,粘贴 ...

  2. C#中对字符串的加密和解密

    加密: /// <summary> /// 对字符串进行加密 /// </summary> /// <param name="proclaimText" ...

  3. 【译】Nodejs最好的ORM

    TypeORM github: https://github.com/typeorm/typeorm这篇译文是从TypeORM github上的使用说明上翻译过来的,已经提交PR并merge到库中了. ...

  4. [NOIP2002] 提高组 洛谷P1034 矩形覆盖

    题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...

  5. Android视图组成View

    视图组成View 创建时间: 2013-9-13 10:51 更新时间: 2013-9-13 11:04

  6. msp430项目编程31

    msp430中项目---无线通信系统31 1.SPI工作原理 2.nrf24l01工作原理 3.代码(显示部分) 4.代码(功能实现) 5.项目总结

  7. ThinkPHP5 的入门学习

    与Tp3.2相比,有一下的不同: (1)目录名称的改变: tp3.2的目录命名首字母皆为大写,例如:Application.Public.Controller.Model.View.ThinkPHP. ...

  8. MAC地址泛红攻击

    一.环境 IP地址: Windows10   IP:10.13.153.55 Windows7:   IP:192.168.83.130 Linux:       IP:192.168.83.129 ...

  9. 【深度探索c++对象模型】Function语义学之虚函数

    虚函数的一般实现模型:每一个class有一个virtual table,内含该class中的virtual function的地址,然后每个object有一个vptr,指向virtual table. ...

  10. js实现动态删除表格的行或者列-------Day57

    昨天记录了动态加入表格的一行,当然这个一行是指一行数据,也就是说一行多少列也是加上的,而且第几列的内容都能够加入上,先来回想下它的实现的关键点: 1.var row=table.insertRow() ...