第十三周任務三

2021-06-06 12:26:33 字數 1120 閱讀 6016

寫乙個程式,定義抽象基類shape,由它派生出3個派生類,circle(圓形)、rectangle(矩形)、********(三角形)。用如下的mian()函式,求出定義的幾個幾何體的面積和。

int main()

; //定義基類指標陣列pt,各元素指向乙個派生類物件

double areas=0.0; //areas為總面積

for(int i=0; i<6; i++)

cout<

解答:#include #define pi 3.14159

using namespace std;

class shape

;class circle : public shape

; virtual double area() const;

private:

float radius;

};double circle::area() const

class rectangle : public shape

; virtual double area() const;

private:

float length;

float width;

};double rectangle::area() const

class ******** : public shape

; virtual double area() const;

private:

float base;

float height;

};double ********::area() const

int main()

; //定義基類指標陣列pt,各元素指向乙個派生類物件

double areas = 0.0; //areas為總面積

for(int i = 0; i < 6; i++)

cout << "totol of all areas=" << areas << endl; //輸出總面積

system("pause");

return 0;

}

上機感言:儘管「形狀」沒有具體的面積,但他當上了圓、矩形的頭。

第十三周任務(三)

include iostream includeusing namespace std class shape class circle public shape private double r double circle area const class rectangle public sha...

第十三周 任務二

程式頭部注釋開始 程式的版權和版本宣告部分 檔名稱 抽象類 作 者 薛廣晨 完成日期 2012 年 5 月 11 日 版 本 號 x1.0 對任務及求解方法的描述部分 輸入描述 使用抽象類 問題描述 任務2 下面給出了基類animal和main 函式。任務2.1 根據main 函式給出的注釋提示,設...

第十三周實驗報告(任務三)

三角函式表 作 者 張培培 完成日期 2012年 03月 05日 版本號 對任務及求解方法的描述部分 輸入描述 無 問題描述 編制乙個三角函式表,要求在main 函式中呼叫show sin table min angle,max angle 顯示角度值為min angle到max angle之間的所...