第十周实验报告3(派生类+流输入输出-->求圆柱体的面积与体积)

程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:      (派生类+流输入输出-->求圆柱体的面积与体积)     
* 作    者:     王智凯                       
* 完成日期:  2012年    4  月  23  日
* 版 本 号:  凯子

 

#include <iostream>

using namespace std;

const double pi =3.14;
class Point 
{
public:
	Point(){x=0;y=0;}
	Point(double x0,double y0) {x=x0; y=y0;} 
	~Point();
protected:
	double x;
	double y;
};

class Circle:public Point
{
public:
	Circle(double x, double y,double radius=0):Point(x,y){r=radius;}
	~Circle();
protected:
	double r;
};

class Cylinder:public  Circle
{
public:
	Cylinder(double x,double y,double r,double height=0):Circle(x,y,r){h=height;}
	~Cylinder();
	double area();
	double voluem();
	friend ostream &operator<<(ostream &output,Cylinder c);
private:
	double h;
};

Point ::~Point(){}

Circle::~Circle(){}

Cylinder::~Cylinder(){}

double Cylinder::area()
{
	return (pi * 2 * r * h + pi * r * r);
}

double Cylinder::voluem()
{
	return (pi * r * r * h);
}

ostream &operator<<(ostream &output,Cylinder c)
{
	output<<"坐标点为:"<<"("<<c.x<<","<<c.y<<")"<<endl;
	output<<"圆柱体底面半径为:"<<c.r<<endl;
	output<<"圆柱体高为:"<<c.h<<endl;
	output<<"圆柱体表面积是:"<<c.area()<<endl;
	output<<"圆柱体体积是:"<<c.voluem()<<endl;
	return output;
}

void main()
{
	Cylinder c(2,3,4,7);
	cout<<"请输入点坐标格式(x x)、半径、高:"<<endl;
	cin>>c;
	cout<<c;
	system("pause");
}


上机感言:1.又一次体会了流输出,这次老师没提供开头一下感觉不太适应了,呵呵,,可能是依赖性太强了吧

                 2.总觉得写的这个程序不太对,是不合题意还是?阅读老师程序后在修改吧。。。。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值