/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 作 者: 高中亚
* 完成日期: 2012 年 4 月 23日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 作 者: 高中亚
* 完成日期: 2012 年 4 月 23日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
#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;
}
感言:用标记的方法取黑框子上的结果不靠谱啊.......