第十周任务(3)

#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;  
}  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值