/*
**************************************************************
*
* 程序名称:GeoMetricShape
* 功能 :多态实例测试
* 作者 :愤怒的小马
*
* 说明: GeoMetricShape 是一个纯虚类 提供接口继承。
*
**************************************************************
*/
#include <iostream>
using namespace std;
#define P 3.1415926
const double EPSINON = 0.00001;
class GeoMetricShape
{
public:
GeoMetricShape():m_fCircum(0.00f),m_fArea(0.00f)
{
}
virtual ~GeoMetricShape();
virtual double& GetCircumference()=0;
virtual double& GetArea() = 0;
virtual void print() const;
void who_am_i();
virtual void PrintName() const;
protected:
double m_fCircum;
double m_fArea;
};
GeoMetricShape::~GeoMetricShape()
{
}
void GeoMetricShape::print()const
{
}
void GeoMetricShape::who_am_i()
{
PrintName();
}
void GeoMetricShape::PrintName()const
{
cout << "未知的类型" << endl;
}
class Circle:public GeoMetricShape
{
private:
double m_fRadius;
public:
Circle()
{
cout << "输入圆的半径:";
cin >>m_fRadius;
}
Circle(const double & radius):m_fRadius(radius)
{
}
~Circle()
{
}
double& GetCircumference()
{
m_fCircum = 2*P*m_fRadius;
return m_fCircum;
}
double& GetArea()
{
m_fArea = P*m_fRadius*m_fRadius;
return m_fArea;
}
void PrintName() const
{
cout << "正圆" << endl;
}
void print() const
{
cout << "正圆(r= "<< m_fRadius <<") 周长 ="
<< m_fCircum<< " 面积= " << m_fArea << endl;
}
};
代码长了 贴不上来。需要下载附件