第11周项目4

#include<iostream>
using namespace std;
class Point //定义坐标点类
{
public:
    Point():x(0),y(0) {};
    Point(double x0, double y0);
    void setPoint(double a,double b);
    double get_x0();
    double get_y0();
    friend ostream & operator<<(ostream &,const Point &);
protected:
    double x,y;   //点的横坐标和纵坐标
};
Point::Point(double x0, double y0)
{
    x=x0;
    y=y0;
}
void Point::setPoint(double a,double b)
{
    x=a;
    y=b;
}
ostream & operator<<(ostream &output,const Point &p)
{
    output<<"("<<p.x<<","<<p.y<<")"<<endl;
    return output;
}
double Point::get_x0()
{
    return x;
}
double Point::get_y0()
{
    return y;
}
class Circle: public Point   //利用坐标点类定义直线类, 其基类的数据成员表示直线的中点
{
public:
    Circle(double x=0,double y=0,double r=0);
    void setRadius(double);
    double area();
    double getr();
    friend ostream &operator<<(ostream &,Circle &);
protected:
    double radius;
};
Circle::Circle(double x,double y,double r)
    :Point(x,y),radius(r) {}
void Circle::setRadius(double r)
{
    radius=r;
}
double Circle::getr()
{
    return radius;
}
double Circle::area()
{
    return 3.14*radius*radius;
}
ostream &operator<<(ostream &output,Circle &c)
{
    output<<"圆的圆心是"<<'('<<c.x<<','<<c.y<<"),r="<<c.radius<<" area="<<c.area();
    return output;
}
class Cylinder:public Circle
{
public:
    Cylinder(double x=0,double y=0,double r=0,double h=0);
    double area();
    double volume();
    double geth();
    void setHeight(double);
    friend ostream &operator<<(ostream &,Cylinder &);
private:
    double height;
};
Cylinder::Cylinder(double x,double y,double r,double h)
    :Circle(x,y,r),height(h) {}
void Cylinder::setHeight(double h)
{
    height=h;
}
double Cylinder::area()
{
    return 2*3.14*radius+height+Circle::area();
}
double Cylinder::volume()
{
    return Circle::area()*height;
}
ostream &operator<<(ostream &output,Cylinder &cy)
{
    output<<"Center=("<<cy.x<<","<<cy.y<<"), r="<<cy.radius<<", h="<<cy.height
          <<"\narea="<<cy.area( )<<", volume="<<cy.volume( )<<endl;
    return output;
}
double Cylinder::geth()
{
    return height;
}
int main()
{
    Cylinder cy1(1,1,5.2,10);
    cout<<"\ncylinder:\nx="<<cy1.get_x0( )<<", y="<<cy1.get_y0( )<<", r="
        <<cy1.getr( )<<", h="<<cy1.geth( )<<"\narea="<<cy1.area()
        <<",volume="<<cy1.volume()<<endl;
}


 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值