程序头部注释开始
* 程序的版权和版本声明部分
* 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.总觉得写的这个程序不太对,是不合题意还是?阅读老师程序后在修改吧。。。。。。