RW········3

#include < iostream >

using namespace std;

class Point

{

protected:

	double x;

	double y;

public:

	Point ( double m, double n );

	void Show1( );

	~Point( );              //需要释放建立对象时动态分配的内存

};

class Circle : public Point

{protected:

	double r;

public:

	Circle ( double m,double n,double c);

	void Show2( );

	~Circle( );

};

class Cylinder : public Circle

{protected:

	double h;

public:

	Cylinder ( double m,double n,double c,double d);

	void Show3( );

	double get_s();

	double get_v();

	~Cylinder( );

	friend ostream & operator << (ostream&,Cylinder &c);

};
Point::Point ( double m, double n )
{
	x=m;
	y=n;
}

void Point::Show1( )
{
	cout<<"("<<x<<","<<y<<")"<<endl;
}

Point::~Point( )    
{
	cout << "The destructor of part was called "  << endl;

}
Circle::Circle ( double m,double n,double c):Point (  m,  n )
{
	r=c;
}

void Circle::Show2( )
{
	cout<<"("<<x<<","<<y<<")"<<"半径:"<<r<<endl;
}

Circle::~Circle( )
{
	cout << "The destructor of part was called "  << endl;
}

Cylinder::Cylinder ( double m,double n,double c,double d):Circle (  m, n, c)
{

	h=d;
}

void Cylinder::Show3( )
{
	cout<<"("<<x<<","<<y<<")"<<"半径:"<<r<<"高:"<<h<<endl;
}

double Cylinder::get_s()
{
	double s=0;

	double i=3.14;

	s=r*r*i;

	cout << "面积为:" << s << endl;

	return s;
}

double Cylinder::get_v()
{
	double v=0;

	double j=3.14;

	v=r*r*j*h;

	cout << "体积为:" << v <<endl; 

	return v;
}


Cylinder::~Cylinder( )

{

	cout << "The destructor of part was called "  << endl;

}


ostream & operator << (ostream&output,Cylinder &c)

{
	output<<"("<<c.x<<","<<c.y<<")"<<endl;

	output<<"半径"<<c.r<<endl;

	output<<"高"<<c.h<<endl;

	return output;
}


int main( )

{

	double a,b,c,d;

	cout << "请分别输入坐标对应的x,y及其圆柱的半径和高"<<endl;

	cin >> a >> b >> c >> d ;

	Cylinder cylinder( a,b,c,d );

	cylinder.Show3( );

	cylinder.get_s();

	cylinder.get_v();

	cout<<cylinder;

	system ( "pause" );

	return 0;

}

运行结果:

 

请分别输入坐标对应的x,y及其圆柱的半径和高
0 0 1 1
(0,0)半径:1高:1
面积为:3.14
体积为:3.14
(0,0)
半径1
高1
请按任意键继续. . .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值