第十周实验报告 任务三(改)

源程序:

#include<iostream>

#include<Cmath>

//#define P 3.14  宏定义是c语言里的····

const double P = 3.14;//c++应该用const

using namespace std;

class Point //定义坐标点类
{
protected:

	double x, y;   //点的横坐标和纵坐标

public:

	Point(){x=0;y=0;}

	Point(double x0, double y0);

	~Point();

	double getx();

	double gety();
};  

class Circle: public Point//定义圆类
{
protected:

	double r;//定义圆的半径

public:

	Circle(){x=0; y=0; r=0;}

	Circle(double x0, double y0, double r0);

	~Circle();

	double getr();

	double Area();

	double Grith();
};

class Cylinder:public Circle//定义圆柱类
{
protected:

	double h;//定义圆柱类的高

public:

	Cylinder(){x=0; y=0; r=0; h=0;}

	Cylinder(double x0, double y0, double r0, double h0);

	~Cylinder();

	double geth();

	double Volume();

	double WArea();

	friend istream& operator >> (istream& input, Cylinder &c1);

	friend ostream& operator << (ostream& output, Cylinder &c1);
};

Point::Point(double x0, double y0):x(x0), y(y0){}

Point::~Point(){}

double Point::getx()
{
	return x;
}

double Point::gety()
{
	return y;
}

Circle::Circle(double x0, double y0, double r0):Point(x0, y0),r(r0){}

Circle::~Circle(){}

double Circle::getr()
{
	return r;
}

double Circle::Area()
{
	return P * getr() * getr();
}

double Circle::Grith()
{
	return P * getr() * 2;
}

Cylinder::Cylinder(double x0, double y0, double r0, double h0):Circle(x0, y0, r0), h(h0){}

Cylinder::~Cylinder(){}

double Cylinder::geth()
{
	return h;
}

double Cylinder::Volume()
{
	return Area() * h;
}

double Cylinder::WArea()
{
	return (2 * Area() + Grith() * h);
}

istream& operator >> (istream& input, Cylinder &c1)
{
	char f;

	while(1)
	{
		cout << "请输入一个圆柱底面○的圆心坐标(x和y之间用','隔开):";

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

		if(f != ',')
		{
			cout << "输入格式有误。。。" << endl;
		}

		else
			break;
	}

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

	input >> c1.r;

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

	input >> c1.h;

	return input;
}

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;

	cin >> c;

	cout << c;

	system("pause");

	return 0;
}


截图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值