0 thích 0 k thích
132 đã xem

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

 

[Normal] Coding (C++) - đã hỏi trong Introduction to Computer Programming II (C++)
ID: 52070 - Xem được từ: 2018-04-26 17:48 - Hiệu lực đến: Không giới hạn
| 132 đã xem
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.58.238
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
0 trả lời
[Normal] Coding (C++) - đã hỏi ngày 17 tháng 5 năm 2018 trong Introduction to Computer Programming II (C++)
ID: 52071 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 142 đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên