第十周任务三

#include <iostream>                          //点类
using namespace std;
const double pi = 3.1415926;
class Point
{
protected:
	double x;
	double y;
public:
	Point() {x = 0;  y = 0;}
	Point (double x0,double y0):x(x0),y(y0){}
	~Point(){}
	double Getx()
	{
		cin >> x;
		return x;
	}
	double Gety()
	{
		cin >> y;
		return y;
	}
	friend ostream & operator<<(ostream &,Point &);
	
};




class Circle:public Point                  //圆类
{
protected:
	double r;
public:
	Circle() {x = 0; y = 0; r = 0;}
	Circle(double x0,double y0,double r0):Point( x0,y0),r(r0){}
	double Getr()
	{
		cin >> r;
		return r;
	}
	double area();
	friend ostream & operator<<(ostream &,Circle &);
};




 
class Cylinder:public Circle                         //圆柱类
{
private:
	double h;
public:
	Cylinder() { x = 0; y = 0; r = 0; h = 0;}
	Cylinder(double x0,double y0,double r0,double h0):Circle( x0,y0,r0),h(h0){}
	double Geth()
	{
		cin >> h;
		return h;
	}
	double areaCylinder();
	double volumeCylinder();
	friend ostream & operator<<(ostream &, Cylinder&);
};

ostream & operator<<(ostream &output, Point &p)             //输出流函数定义
{  
    output<<"("<<p.x<<","<<p.y<<")"<<endl;  
    return output;  
}  

ostream &operator<<(ostream &output, Circle &p)              //输出流函数定义
{  
    output<<"Center=("<<p.x<<", "<<p.y<<"), r="<<p.r<<", area="<<p.area( )<<endl;  
    return output;  
}  

ostream &operator<<(ostream &output, Cylinder& p)              //输出流函数定义
{  
    output<<"Center=("<<p.x<<","<<p.y<<"), r="<<p.r<<", h="<<p.h  
        <<"area="<<p.areaCylinder( )<<", volume="<<p.volumeCylinder( )<<endl;  
    return output;  
} 



double Circle::area()  
{                                                                       //圆的面积函数定义     
	return (pi * r * r);
}



double Cylinder::areaCylinder()                          //圆柱的面积函数定义
{
	return (2 * Circle::area() + 2 * pi * r * h);

}
double Cylinder::volumeCylinder()                        //圆柱的体积函数定义
{
	return (Circle::area() * h);
}



int main()                                                 //主函数定义
{
	Cylinder c1(3,4,5,6),c2;                               //定义圆柱对象

	cout << "请输入相关数值:(x,y,r,h)" << endl;
	c2.Getx();
	c2.Gety();
	c2.Geth();
	c2.Getr();

	cout << "area1=" << c1.areaCylinder() << endl;
	cout << "volume1=" << c1.volumeCylinder() << endl << endl;
	cout << "area2=" << c2.areaCylinder() << endl;
	cout << "volume2=" << c2.volumeCylinder() << endl;

	system("pause");
	return 0;
}

	



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值