项目4 - 类族的设计

*烟台大学计算机学院学生
*All right reserved.
*文件名称*烟台大学计算机学院学生
*All right reserved.
*文件名称:项目4 - 类族的设计
*作者:杨飞
*完成日期:2014年5月5日
*版本号:v1.0
*对任务及求解方法的描述部分:项目4 - 类族的设计
*我的程序:
#include <iostream>
using namespace std;
const double pi=3.14;
class point
{
protected:
    int x,y;
public:
   point(double x1=0,double y1=0);
   void setpoint(double x1,double y1);
   friend ostream &operator <<(ostream &output,point &c);
   double getx()
    {
       return x;
    }
    double gety()
    {
       return y;
    }
};
point::point(double x1,double y1)
{
    x=x1;
    y=y1;
}
void point::setpoint(double x1,double y1)
{
     x=x1;
     y=y1;
}
ostream &operator <<(ostream &output,point &c)
{
    output<<"("<<c.x<<","<<c.y<<")"<<endl;
    return output;
}
class circle :public point
{
protected:
    double r;
public:
    friend ostream &operator<<(ostream &output,circle &c);
    circle(int x1,int y1,double a):
    point(x1,y1),r(a){};
     void setr(double a);
     double getr();
     double area();
};
void circle::setr(double a)
{
    r=a;
}
double circle::getr()
{
    return r;
}
double circle::area()
{
    double s;
    s=pi*r*r;
    return s;
}
ostream &operator<<(ostream &output, circle &c)
{
    output<<"yuanxin=("<<c.x<<", "<<c.y<<"), r="<<c.r<<", area="<<c.area( )<<endl;
    return output;
}
class cylinder:public circle
{
private:
    double h;
public:
   friend ostream &operator<<(ostream &output,cylinder &c);
    cylinder(double x1,double y1,double a,double b):
    circle(x1,y1,a),h(b){};
    void seth(double b);
    double geth();
    double area1();
    double volume();
};
void cylinder::seth(double b)
{
    h=b;
}
double cylinder::geth()
{
    return h;
}
double cylinder::area1()
{
    double s;
    s=2*area()+2*pi*r*h;
    return s;
}
double cylinder::volume()
{
    double v;
    v=area()*h;
    return v;
}
ostream &operator<<(ostream &output,cylinder &c)
{
    output<<"yuanxin=("<<c.x<<", "<<c.y<<"), r="<<c.r<<endl;
    output<<"表面积="<<c.area1( )<<"体积="<<c.volume()<<endl;
    return output;
}
int main()
{
   cout<<"原来的数据和结果:"<<endl;
   cylinder t(3,1,5.2,10);
   cout<<"圆心坐标="<<endl;
   cout<<"x="<<t.getx()<<endl;
   cout<<"y="<<t.gety()<<endl;
   cout<<"半径="<<t.getr()<<endl;
   cout<<"底面面积="<<t.area()<<endl;
   cout<<"表面积="<<t.area1()<<endl;
   cout<<"体积"<<t.volume()<<endl;
   cout<<"更改半径,坐标,和高后的运行结果:"<<endl;
     t.seth(12);
     t.setr(6);
     t.setpoint(4,2);
     cout<<t;
     return 0;
}


运行结果:

心得体会:呵呵

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值