第十一周

#include <iostream>
using namespace std;
class Point
{
    public:
    Point(double a=0,double b=0);
    void SetPoint(double,double);
    double getX() const {return x;}
    double getY() const {return y;}
    void ShowPoint();
    friend ostream & operator<<(ostream &output,const Point &c);
    protected:
    double x,y;
};
Point::Point(double a,double b)
{
    x=a;
    y=b;
}
void Point::SetPoint(double x1,double y1)
{
    x=x1;
    y=y1;
}
void Point::ShowPoint()
{
    cout<<"Point: ("<<x<<","<<y<<")"<<endl;
}
ostream & operator<<(ostream &output,const Point &c)
{
    output<<"point: ("<<c.x<<","<<c.y<<")"<<endl;
    return output;
}
class Circle:public Point
{
   public:
   Circle(double a,double b,double c):Point(a,b),r(c){}
   void SetCircle(double r2);
   double Getr(){return r;}
   double area();
   void ShowCircle();
   friend ostream & operator<<(ostream &,const Circle &C);
   protected:
   double r;
};
void Circle::SetCircle(double r2)
{
    r=r2;
}
double Circle::area()
{
    return 3.1415*r*r;
}
void Circle::ShowCircle()
{
    cout<<"Circle: ("<<x<<","<<y<<") r="<<r<<endl;
}
ostream & operator<<(ostream &output,const Circle &C)
{
    output<<"Circle: ("<<C.x<<","<<C.y<<") r="<<C.r<<endl;
    return output;
}
class Cylinder:public Circle
{
    public:
    Cylinder(double x3,double y3,double r3,double h3):Circle(x3,y3,r3),h(h3){}
    void setheight(double);
    double GetCylinder();
    double area();
    double volume();
    friend ostream &operator<<(ostream &,  Cylinder &);
    protected:
    double h;
};
void Cylinder::setheight(double h1)
{
    h=h1;
}
double Cylinder::GetCylinder()
{
    return h;
}
double Cylinder::area()
{
    return 2*3.1415*r*r+3.1415*2*r*h;
}
double Cylinder::volume()
{
    return 3.1415*r*r*h;
}

ostream &operator<<(ostream &output, Cylinder &cy)
{
    output<<"cylinder: ("<<cy.x<<","<<cy.y<<") r="<<cy.r<<" height="<<cy.h<<" area="<<cy.area()<<" volume="<<cy.volume()<<endl;
    return output;
}
int main()
{
    Cylinder cy(3.5,6.4,5.2,10);
    cout<<"cylinder: POINT:("<<cy.getX()<<","<<cy.getY()<<") r="<<cy.Getr()<<" height="<<cy.GetCylinder()<<" are="<<cy.area()<<" volume="<<cy.volume()<<endl;
    cy.setheight(15);
    cy.SetCircle(7.5);
    cy.SetPoint(5,5);
    cout<<"cylinder: "<<cy<<endl;
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值