資源簡介
C++實戰(zhàn)源碼-計算幾何圖形的面積(入門級實例213).zip
代碼片段和文件信息
//?area.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“math.h“
#include?“iostream.h“
#include?“string.h“
const?double?PI?=?3.1415926;
class?Shape?{
protected:
char?name[30];
public:
Shape(){strcpy(name“Shape“);}
char?*?getName()?{//獲得圖形的名稱
????????return?name;
????}
public:
virtual?double?getArea()?=?0;//獲得圖形的面積
};
class?Circle?:public?Shape?{
private:
double?m_radius;
public:
Circle(double?radius)?{//獲得圓形的半徑
strcpy(name“Circle“);
????????m_radius?=?radius;
????}
????double?getArea()?{//計算圓形的面積
????????return?PI?*?pow(m_radius?2);
????}
};
class?Rectangle?:public?Shape?{
private:
double?m_length;
????double?m_width;
public:
Rectangle(double?length?double?width)?{//獲得矩形的長和寬
????????m_length?=?length;
????????m_width?=?width;
strcpy(name“Rectangle“);
????}
????double?getArea()?{//計算矩形的面積
????????return?m_length?*?m_width;
????}
};
int?main(int?argc?char*?argv[])
{
C
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1399??2010-10-14?10:43??area\area.cpp
?????文件????????4512??2010-10-14?10:26??area\area.dsp
?????文件?????????533??2010-10-14?10:26??area\area.dsw
?????文件?????????291??2010-10-14?10:26??area\StdAfx.cpp
?????文件?????????769??2010-10-14?10:26??area\StdAfx.h
評論
共有 條評論