#include <iostream>
using namespace std;
class Point
{
public:
Point(double a,double b):x(a),y(b){}
void setPoint(double a,double b);
double getX(){return x;}
double getY(){return y;}
protected:
double x;
double y;
};
class Circle:public Point
{
public:
Circle(double a,double b,double c):Point(a,b),r(c){}
void setR(double);
double getR(){ return r;}
double area(){ return (3.14*r*r);}
/*friend ostream &operator <<(ostream &,Ciecle &);*/
protected:
double r;
};
class Cylinder:public Circle
{
public:
Cylinder(double a,double b,double c,double d):Circle(a,b,c),h(d){}
void setH(double);
double getH(){return h;}
double s();
double v();
friend ostream &operator <<(ostream &,Cylinder &);
protected:
double h;
};
void Circle::setR(double c)
{
r=c;
}
void Point::setPoint(double a,double b)
{
x=a;
y=b;
}
/*ostream &operator <<(ostream &output,Ciecle &c)
{
output<<"Center=["<<c.x<<","<<c.y<<"],r="<<c.r<<",area"<<c.area()<<endl;
return output;
}*/
void Cylinder::setH(double d)
{
h=d;
}
double Cylinder::s()
{
return (2*area()+3.14*2*r*h);
}
double Cylinder::v()
{
return (area()*h);
}
ostream &operator <<(ostream &output,Cylinder &c)
{
output<<"Center=["<<c.x<<","<<c.y<<"],r="<<c.r<<",h"<<c.h<<",area"<<c.s()<<",volume="<<c.v()<<endl;
return output;
}
int main( )
{
Cylinder c1(3.5,6.4,5.2,10);
cout<<"\noriginal cylinder:\nx="<<c1.getX( )<<", y="<<c1.getY( )<<", r="
<<c1.getR( )<<", h="<<c1.getH( )<<"\narea="<<c1.s()
<<",volume="<<c1.v()<<endl;
c1.setH(15);
c1.setR(7.5);
c1.setPoint(5,5);
cout<<"\nnew cylinder:\n"<<c1;
system("pause");
return 0;
}
第十周任务(3)
最新推荐文章于 2022-02-25 21:57:21 发布