一些C++的课件和实验源代码
源代码在线查看: figure.h
#ifndef HEADFILE_FIGURE
#define HEADFILE_FIGURE
class figure // 图形类
{
public:
virtual int GetPerimeter() {return 0;} // 计算周长
virtual int GetArea() {return 0;} // 计算面积
};
class circle: public figure // 圆类
{
protected:
int m_nRadius; // 圆半径
public:
circle(int radius) {m_nRadius = radius;}
int GetPerimeter(){ // 计算周长
return (int)(2 * 3.1416 * m_nRadius);
}
int GetArea(){ // 计算面积
return (int)(3.1416 * m_nRadius * m_nRadius);
}
};
class square: public figure // 矩形类
{
protected:
int m_nLength; // 边长
public:
square(int length) {m_nLength = length;}
int GetPerimeter(){ // 计算周长
return 4 * m_nLength;
}
int GetArea(){ // 计算面积
return m_nLength * m_nLength;
}
};
#endif