第十周 任务三

#include<iostream>
#define pi 3.1415
using namespace std;
class Point
{
public:
	int x;
	int y;
//public:
	Point (int xx = 0, int yy = 0):x(xx), y(yy){};
	~Point();
	void setPoint(int a, int b);
	friend ostream & operator << (ostream & out, Point &a);

};
Point::~Point ()
{

}
ostream & operator << (ostream & out, Point & a)
{
	out << "(" << a.x << "," << a.y << ")" << endl;
	return out;

}
void Point::setPoint (int a, int b)
{
	x = a;
	y = b;
}
class Circle: public Point 
{
public:
	int r;
public:
	Circle (int xx, int yy, int r1):Point (xx, yy){r = r1;}
	~Circle();
	void setCircle(int a, int b, int c);
	friend ostream & operator << (ostream & out, Circle & a);

};

Circle::~Circle()
{

}

void Circle::setCircle(int a, int b, int c)
{
	x = a;
	y = b;
	r = c;
}

ostream & operator << (ostream & out, Circle & a)
{
	out << "圆心:"<< "(" << a.x << "," << a.y << ")" << endl;
	out << "半径:" << a.r;
	return out;
}
class Cylinder: public Circle
{
private:
	int h;
public:
	Cylinder(int xx, int yy, int r1, int h1):Circle(xx, yy, r1){h = h1;}
	~Cylinder();
	void setCylinder(int a, int b, int c, int d);
	friend ostream & operator << (ostream &out, Cylinder &a);
	double Carea();
	double Cvolume();
};
Cylinder::~Cylinder()
{

}

void Cylinder::setCylinder(int a, int b, int c, int d)
{
	x = a;
	y = b;
	r = c;
	h = d;
}
ostream & operator << (ostream &out, Cylinder &a)
{
	out <<"圆心:" << "("<< a.x <<"," <<a.y <<")" << endl;
	out<<"半径:" << a.r << endl;
	out<< "高: " << a.h << endl;
	return out;
}

double Cylinder::Carea()
{
	double m;
	m = 2 * r * pi;
	return (m * h);
}

double Cylinder::Cvolume()
{
	return (r * r * pi * h);
}
int main()
{
	Cylinder c(2, 2, 2 ,2);
	cout << c;
	cout<< "表面积:" << c.Carea () << endl;
	cout << "体积:" << c.Cvolume () << endl;
	system("pause");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值