第十周实验报告 任务三

源程序:

#include<iostream>

#include<Cmath>

#define P 3.14

using namespace std;

class Point //定义坐标点类
{
protected:
	
	double x, y;   //点的横坐标和纵坐标
	
public:
	
	Point(double x0, double y0):x(x0), y(y0){}
	
	~Point(){}
	
	double getx()
	{
		return x;
	}
	
	double gety()
	{
		return y;
	}
};  

class Circle: public Point//定义圆类
{
protected:
	
	double r;//定义圆的半径
	
public:
	
	Circle(double x0, double y0, double r0):Point(x0, y0),r(r0){}
	
	~Circle(){}
	
	double getr()
	{
		return r;
	}
	
	double Area()
	{
		return P * getr() * getr();
	}
	
	double Grith()
	{
		return P * getr() * 2;
	}
	
};

class Cylinder:public Circle//定义圆柱类
{
protected:
	
	double h;//定义圆柱类的高
	
public:
	
	Cylinder(double x0, double y0, double r0, double h0):Circle(x0, y0, r0), h(h0){}
	
	~Cylinder(){}
	
	double geth()
	{
		return h;
	}
	
	double Volume()
	{
		return Area() * h;
	}
	
	double WArea()
	{
		return (2 * Area() + Grith() * h);
	}
	
/*	friend istream& operator >> (istream& input, Cylinder &c1)
	{
		cout << "请输入一个圆柱底面○的圆心坐标(x和y之间用空格隔开):";

		input >> c1.x >> c1.y;

		cout << endl;

		cout << "请输入一个圆柱底面○的半径:";

		input >> c1.r;

		cout << endl;

		cout << "请输入一个圆柱的高";

		input >> c1.h;

		return input;
	}
*/	
	friend ostream& operator << (ostream& output, Cylinder &c1)
	{
		output << "圆柱底面○的圆心为:" << "(" << c1.getx() << "," << c1.gety() << ")" << endl;
		
		output << "圆柱底面○的半径为:" << c1.getr() << endl;
		
		output << "圆柱底面○的面积为:" << c1.Area() << endl;
		
		output << "圆柱底面○的周长为:" << c1.Grith() << endl;
		
		output << "圆柱的高为:" << c1.geth() <<endl;
		
		output << "圆柱的表面积为:" << c1.WArea() << endl;
		
		output << "圆柱的体积为:" <<c1.Volume() << endl;
		
		return output;
	}
};

int main()
{
	Cylinder c(0, 1, 2, 3);
	
	cout << c;

	system("pause");
	
	return 0;
}


截图:

函数都是在类里面直接定义了···因为一开始觉得做不出来,只是想做做试试···后来有思路了···可是太晚了,逸夫要关门了···哎···忘记带优盘或者下载线了···只好发了···纠结····为什么我重载">>"不行呢?奇怪···

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值