0 喜歡 0 不喜歡
128 瀏覽

Write class shape with width and height following a constructor that gives value to them.
Then define two sub-classes triangle and rectangle.
Those sub-classes can calculate the area of the shape area().
You need to follow the main() below without any changes. Please complete the program.

請寫個shape類別,在shape類別中宣告長度和寬度變數並定義一個建構函式為設定長度和寬度的值。

定義兩個子類別triangle和rectangle來計算三角形和長方形的面積。

請使用下列main()函數完成本程式。(禁止修改main函數)

int main (){
    Rectangle rect;
    Triangle tri;
    int w1,h1,w2,h2;
    cin >> w1 >> h1 >> w2 >> h2;
    rect.set_data (w1,h1);
    tri.set_data (w2,h2);
    cout << rect.area() << ";" << tri.area();
    return 0;
}

Example input:

5 3 2 5

Example output:

15;5

 

[正常] Coding (C++) - 最新提問 分類:Introduction to Computer Programming II (C++) |
ID: 52070 - 從幾時開始: 2018-04-26 17:48 - 到幾時結束: 無限制
| 128 瀏覽
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:108.162.216.77
©2016-2024

相關問題

0 喜歡 0 不喜歡
0 回答
[正常] Coding (C++) - 最新提問 5月 17, 2018 分類:Introduction to Computer Programming II (C++) |
ID: 52071 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 141 瀏覽
12,783 問題
183,443 回答
172,219 留言
4,824 用戶