0 like 0 dislike

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++)
Available when: 2018-04-26 17:48 - Due to: Unlimited
| 3 views
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.63.39
©2016-2019

Related questions

0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
[Normal] Coding (C++) - asked May 17, 2018 in Introduction to Computer Programming II (C++)
Available when: Unlimited - Due to: Unlimited
| 18 views
8,384 questions
65,920 answers
40,347 comments
1,516 users