码迷,mamicode.com
首页 > 其他好文 > 详细

第11周项目1——点、圆、圆柱类的设计

时间:2016-05-13 00:01:19      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:

<pre class="html" name="code">


/*

*Copyright (c) 2016,烟台大学计算机学院

*All rights reserved.

*文件名称 :

*作 者 : 刘云

*完成日期 : 2016年5月8号

*版 本 号 : v6.0

*

*问题描述 : 点、圆、圆柱类的设计

*输入描述 : 无

*程序输出 :

*/

/*****************************************************(1)******************************************************************/

#include<iostream>

using namespace std;

class Point

{

   public: Point(float i,float j):x(i),y(j){cout<<"setting successfully!!!"<<endl;}\

    float getX(){return x;}

    float getY(){return y;}

    private: float x; float y;

};

int main()

{

     Point p(1,2);

     cout<<"横坐标为:"<<p.getX()<<"\n纵坐标为:"<<p.getY()<<endl;

    return 0;

}


运行结果:

技术分享

/*****************************************************(2)******************************************************************/

//(2)
#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.1415926
class Point
{
public:
    void setPoint(float i,float j);
    float getX(){return x;}
    float getY(){return y;}
    float dr(Point &p1,Point &p2);
private:
    float x;
    float y;
};
void Point::setPoint(float i,float j)
{
    x=i;
    y=j;
}
float Point::dr(Point &p1,Point &p2)
{
    float dr=0,dx=0,dy=0;
    dx=p1.x-p2.x;
    dy=p1.y-p2.y;
    dr=sqrt(dx*dx+dy*dy);
    return dr;
}
class Circle :public Point
{
public:
    Circle(float x1,float y1,float x2,float y2){midpoint.setPoint(x1,y1);aroundpoint.setPoint(x2,y2);}
    float setR();
    void circle_area();
    float getR(){return r;}
private:
    float area;
    float r;
    Point midpoint;
    Point aroundpoint;
};
float Circle::setR()
{
    r=dr(midpoint,aroundpoint);
    return r;
}
void Circle::circle_area()
{
    r=setR();
    area=PI*r*r;
    cout<<"圆的面积为:"<<area<<endl;
}
int main()
{
    Circle c1(0,0,3,4);
    c1.circle_area();
    return 0;
}



运行结果:

技术分享

/*****************************************************(3)******************************************************************/

//(3)
#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.1415926
class Point
{
public:
    void setPoint(float i,float j);
    float getX(){return x;}
    float getY(){return y;}
    float dr(Point &p1,Point &p2);
private:
    float x;
    float y;
};
void Point::setPoint(float i,float j)
{
    x=i;
    y=j;
}
float Point::dr(Point &p1,Point &p2)
{
    float dr=0,dx=0,dy=0;
    dx=p1.x-p2.x;
    dy=p1.y-p2.y;
    dr=sqrt(dx*dx+dy*dy);
    return dr;
}
class Circle:public Point
{
public:
    Circle(float x1,float y1,float x2,float y2){midpoint.setPoint(x1,y1);aroundpoint.setPoint(x2,y2);}
    float setR();
    void circle_area();
    float getR(){return r;}
    float getarea(){return area;}
    float lcircle();
private:
    float area;
    float r;
    Point midpoint;
    Point aroundpoint;
};
float Circle::setR()
{
    r=dr(midpoint,aroundpoint);
    return r;
}
void Circle::circle_area()
{
    r=setR();
    area=PI*r*r;
    cout<<"底面圆的面积为:"<<area<<endl;
}
float Circle::lcircle()
{
    r=setR();
    float l;
    l=2*PI*r;
    return l;
}

class Cylinder:public Circle
{
public:
    Cylinder(float x1,float y1,float x2,float y2,float h1):Circle(x1,y1,x2,y2),h(h1){}
    void cylinderarea();
    void cylinder_volume();
private:
    float h;
};
void Cylinder::cylinderarea()
{
    float s;
    s=2*getarea()+lcircle()*h;
    cout<<"圆柱体的表面积为:"<<s<<endl;
}
void Cylinder::cylinder_volume()
{
    float v;
    v=getarea()*h;
    cout<<"圆柱体的体积为:"<<v<<endl;
}
int main()
{

    Cylinder cy1(0,0,3,4,1.0);
    cy1.circle_area();
    cy1.cylinderarea();
    cy1.cylinder_volume();
    return 0;
}


运行结果;


技术分享



第11周项目1——点、圆、圆柱类的设计

标签:

原文地址:http://blog.csdn.net/jingmin52296358al/article/details/51344629

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!