0 like 0 dislike
238 views

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++) - asked in Introduction to Computer Programming II (C++)
ID: 52070 - Available when: 2018-04-26 17:48 - Due to: Unlimited
| 238 views
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.178.36
©2016-2024

Related questions

0 like 0 dislike
0 answers
[Normal] Coding (C++) - asked May 17, 2018 in Introduction to Computer Programming II (C++)
ID: 52071 - Available when: Unlimited - Due to: Unlimited
| 256 views
12,783 questions
183,443 answers
172,219 comments
4,824 users