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