# 面向对象编程技术(作业题二)

#include <iostream>

#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

class CShape
{
public:
virtual double Area() = 0;  // 求面积
virtual double Perimeter() = 0; // 求周长
};

// 圆
class CCircle : public CShape
{
protected:

public:
{
}

virtual ~CCircle()
{
}

virtual double Area()
{
}

virtual double Perimeter()
{
return 2 * M_PI * m_nRadius;
}
};

// 圆内接正方形
class CSquareInCircle : public CShape
{
protected:

public:
{
}

virtual ~CSquareInCircle()
{
}

virtual double Area()
{
}

virtual double Perimeter()
{
return (4 * sqrt(2.0) * m_nRadius);
}
};

// 圆外接正方形
class CSquareOutCircle : public CShape
{
protected:

public:
{
}

virtual ~CSquareOutCircle()
{
}

virtual double Area()
{
}

virtual double Perimeter()
{
return (4 * 2 * m_nRadius);
}
};

///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
CShape* pShape = NULL;
CCircle circle(3);
CSquareInCircle square1(3);
CSquareOutCircle square2(3);

pShape = &circle;
cout<<"圆的面积: "<<pShape->Area()<<endl;
cout<<"圆的周长: "<<pShape->Perimeter()<<endl;

pShape = &square1;
cout<<"圆内接正方形的面积: "<<pShape->Area()<<endl;
cout<<"圆内接正方形的周长: "<<pShape->Perimeter()<<endl;

pShape = &square2;
cout<<"圆外接正方形的面积: "<<pShape->Area()<<endl;
cout<<"圆外接正方形的周长: "<<pShape->Perimeter()<<endl;

return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：面向对象编程技术(作业题二) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)