第十周任务三

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:                              
* 作    者: 李超                             
* 完成日期:  2012   年  4  月   25  日
* 版 本 号:   01.10.03       


* 对任务及求解方法的描述部分 

* 程序输出:

坐标为:(1,2)
圆ci:坐标为:(1,2)半径为:3
改变后的圆ci:坐标为:(4,5)半径为:6
圆柱cl:坐标为:(2,3)半径为:1高为:4
改变后的圆柱cl:坐标为:(4,5)半径为:6高为:7

* 程序头部的注释结束

*感言:该题 好麻烦, 最终还是不知道析构函数怎么弄                                                                                                                                                                                                                                                              

*/

头文件LCylinder.h

#include <iostream>

using namespace std;

double P = 3.14159;

class Point
{
public:
	Point(double x1 = 0, double y1 = 0): x(x1), y(y1){}//数据初始化
	friend ostream & operator << (ostream &, Point &);//重载<<
	void Change1(double x1,double y1){x = x1;y = y1;}//改变数据
	double GetX(){return x;}//得到x
	double GetY(){return y;}//得到y

private:
	double x;//横坐标
	double y;//纵坐标
};

class Circle:public Point
{
public:
	Circle (double x1 = 0, double y1 = 0, double r1 = 1):Point(x1, y1),r(r1){}
	double GetR(){return r;}//得到半径
	void Change2 (double x1,double y1,double r1){Change1(x1,y1);r = r1;}//改变数据
	friend ostream & operator <<(ostream &, Point &);//重载<<
private:
	double r;//半径
};

class Cylinder:public Circle
{
public:
	Cylinder(double x1 = 0, double y1 = 0,double r1 = 1, double h1 = 1):Circle (x1, y1, r1), h(h1){}
	double GetH(){return h;}//得到高
	double Area();//计算圆柱面积
	double Volume();//计算圆柱体积
	void Change3(double x1,double y1,double r1,double h1){Change2(x1,y1,r1);h = h1;}//改变数据
	friend ostream & operator << (ostream &, Cylinder & c);//重载<<
private:
	double h;//高
};
ostream & operator << (ostream &output, Point & c)
{
	output <<"坐标为:" <<'(' <<c.GetX ()<<',' <<c.GetY () <<')';
	return output;
}

ostream & operator << (ostream &output, Circle & c)
{
	output <<"坐标为:" <<'(' <<c.GetX () <<',' <<c.GetY () <<')' <<"半径为:" <<c.GetR ();
	return output;
}
ostream & operator << (ostream &output, Cylinder & c)
{
	output <<"坐标为:" <<'(' <<c.GetX () <<',' <<c.GetY () <<')' <<"半径为:" <<c.GetR () <<"高为:" <<c.GetH ();
	return output;
}
double Cylinder::Area()
{
	return (2 * GetR () * GetR () * P + 2 * P * GetR () * h);
}
double Cylinder::Volume()
{
	return (2 * GetR () * GetR () * P * h);
}

主函数main.cpp

#include <iostream>
#include"LCylinder.h"

using namespace std;

void main()
{
	Point p1(1,2);
	cout <<p1 <<endl;

	Circle ci(1,2,3);
	cout <<"圆ci:" <<ci <<endl;
	ci.Change2 (4,5,6);
	cout<<"改变后的圆ci:" <<ci <<endl;

	Cylinder cl(2,3,1,4);
	cout <<"圆柱cl:";
	cout <<cl <<endl;
	cl.Change3 (4,5,6,7);
	cout <<"改变后的圆柱cl:";
	cout <<cl <<endl;

	system("pause");
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值