您的位置:首页 > 其它

第十一周项目1-点-圆-圆柱类族的设计(2)

2016-06-05 16:43 323 查看

/* 
 *Copyright (c) 2016,烟台大学计算机学院 
 *All rights reserved. 
 *文件名称:zwj.cpp 
 *作    者:李落才
 *完成日期:2016年6月5日 
 *版 本 号:v1.0 
 * 
 *问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。 
 *输入描述: 
 *程序输出: 
 */  
#include<iostream>  
using namespace std;  
class Point  
{  
public:  
    Point(double a=0,double b=0);  
    void show_point();  
    double getx(){return x;}  
    double gety(){return y;}  
protected:  
    double x;  
    double y;  
};  
class Circle:public Point  
{  
protected:  
    double r;  
public:  
    Circle(double a,double b,double c):Point(a,b),r(c){}  
    double area();  
    void show_circle();  
};  
  
Point::Point(double a,double b)  
{  
    x=a;  
    y=b;  
}  
void Point::show_point()  
{  
    cout<<"点的坐标为:"<<x<<","<<y<<endl;  
}  
double Circle::area()  
{  
    return r*r*3.1415926 ;  
}  
void Circle::show_circle()  
{  
    cout<<"圆的面积为:"<<area()<<endl;  
}  
int main()  
{  
    Point p1(1,2);  
    Circle r1(1,2,2.0);  
    p1.show_point();  
    r1.show_circle();  
  
    return 0;  
}  
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:zwj.cpp
*作    者:张伟晶
*完成日期:2016年5月4日
*版 本 号:v1.0
*
*问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。
*输入描述:
*程序输出:
*/
#include<iostream>
using namespace std;
class Point
{
public:
Point(double a=0,double b=0);
void show_point();
double getx(){return x;}
double gety(){return y;}
protected:
double x;
double y;
};
class Circle:public Point
{
protected:
double r;
public:
Circle(double a,double b,double c):Point(a,b),r(c){}
double area();
void show_circle();
};

Point::Point(double a,double b)
{
x=a;
y=b;
}
void Point::show_point()
{
cout<<"点的坐标为:"<<x<<","<<y<<endl;
}
double Circle::area()
{
return r*r*3.1415926 ;
}
void Circle::show_circle()
{
cout<<"圆的面积为:"<<area()<<endl;
}
int main()
{
Point p1(1,2);
Circle r1(1,2,2.0);
p1.show_point();
r1.show_circle();

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: