#include<iostream>
#include<Cmath>
#define m 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 m * getr() * getr();
}
double Grith()
{
return m* 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;
}
感悟:1.由于某种原因,照片发不上。
2.。通过做这一个题目,发现心里的具体方案是有的,但是真要落实到写的层次来,还真写不对,错误百出。这就叫似是而非。在寒假里 的时候,我把课后题做了一遍,并研究答案不下3遍,之后才发现,c++不过如此。可是现在呢?对于学的新内容,似乎又回到了上学期。对于在电脑上研究老师的答案,那根本不可能。所以我下一步 的做法是把老师给 的答案打印出来,认真研究,光看课本是没有实战效果的,我想这个做法最适合我了,熟能生巧吗!变则通,通则久。