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

914人阅读 评论(0)

#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;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：82824次
• 积分：1134
• 等级：
• 排名：千里之外
• 原创：35篇
• 转载：14篇
• 译文：0篇
• 评论：33条
评论排行
最新评论