第十周任务3

#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++不过如此。可是现在呢?对于学的新内容,似乎又回到了上学期。对于在电脑上研究老师的答案,那根本不可能。所以我下一步 的做法是把老师给 的答案打印出来,认真研究,光看课本是没有实战效果的,我想这个做法最适合我了,熟能生巧吗!变则通,通则久。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值