内存:128  时间:1

题目描述

小聪又想借用小强的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:
"<<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

提示

代码如下

#include<stdio.h>
int main()
{
	printf("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");
}

代码来源于互联网,仅供参考!