0 喜歡 0 不喜歡
4.3k 瀏覽

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. Please complete the program.

int main (){

    Rectangle rect;
    Triangle tri;
    rect.set_data (5,3);
    tri.set_data (2,5);
    cout << rect.area() << ";" << tri.area() << endl;
    return 0;
}

 

[練習] Coding (C) - 最新提問 分類:C++ |
ID: 24389 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶: | 4.3k 瀏覽
0 0
Called for Help
0 0
Called for Help

27 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include ***** * * *



using namespace std;



class shape  {
**** ** ** *
* *** * * * ** *** ******* set_data(int x, int y)
* *** ** *** ****** * * **** * * **
** * ***** *** * * * *** * ** * * * * *** ******** ****** = x;
* * * ** * * ** *** ** ** *** ******* * * ** ** = y;
*** ** *** * ***** * *** *** * * **


* * ** * **** ** *
* * * ** ** ** * ** *** *** * width;
*** * * ** * * ***** *** * * * height;

};



class Rectangle: public shape {
* * ** * * ** *
* * ***** ****** * *** *** ** *** area() {
** ** * ** ***** * * *** *** * * * * ** (width * height);
** ** * ** * **** * *** * ** ****

};



class Triangle: public shape {
* **** * * * ** ****
* * *** * ** * ** **** * ** * area() {
** ** ** **** ***** * *** * * ** ** * *** ** * (width * height / 2);
* ** ** ******* * * *** *****

};



int main(void) {
**** * ** ** * * * * rect;
* ** * * * ** ** * * * tri;


* **** *** * * **** ***** 3);
* * *** ** * *** * 5);


* *** **** * *** * * * * * rect.area() * * ** * * **** ** * * * *** tri.area() * * ***** endl;


* *** **** * 0;

}
最新回答 用戶: (126 分)
0 喜歡 0 不喜歡
內容已隱藏
#include * * * *



using **** std;



class Shape

{
** *
*** ** ***** ***** *** width, height;

public:
** * *** **** * * ** set_data (float a, float b)
* * ******* * * **** ***
**** ** * * ** *** *** * * * ** *** ** ** * * = a;
* * * * ****** ** ** * *** **** * *** ** ** ** = b;
* **** **** * * ***

};



class *** * public Shape

{

public:
* ** *** ** *** * * area ()
** * * ***** * ****
* ** ** * * ***** *** ** ** * * * * *** (width * height);
** * ******** ** ** *

};



class * public Shape

{
*
* * ** * * * * ** * ** area ()
** **** ** **** * * ** ** * *
** ** *** ** ** ** ** **** **** ** * (width * height / 2);
***** * * * *** ****** **

};



int main (){
****** ********* *** * **
* *** ****** ** * * * * rect;
** ** **** *** ** * ** * tri;
* * * **** ** * ** ** * * (5,3);
**** ** * ** ** *** ** * (2,5);
* ** * ** * ** *** *** * ** *** **** * *** * * * * ** * * ** ** ** * * * * ** ******* endl;
*** ***** **** *** ** 0;

}
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
#include ** * ** **



using ** std;



class Shape

{
***
*** * ******* * ** * * * * * width, height;

public:
* ** * ** * * * set_data (float a, float b)
* *** * **** *
* **** ****** * * * * * *** ****** ** * **** = a;
** * * * * ** ***** ** *** * * * = b;
****** ** * * *** *

};



class ** ** public Shape

{

public:
** * * * ***** **** area ()
* * * * * * * **
* ** ******* ** * * * * ****** * * * * ** *** ** ***** (width * height);
*** * * ** * * *** ** ** **

};



class * ***** public Shape

{
**
* * ** ** * *** * * **** area ()
** * * * ** ****
* ** * ** ** ** *** * ** ** **** *** ** * (width * height / 2);
* * *** *

};



int main (){
** * *** * * * **
** * * * ***** * **** rect;
* * ** ***** ** ** ** * ***** * tri;
* ** ** * ** *** * ** * * * * (5,3);
* * **** * * * ***** * (2,5);
* * * * * ** * **** *** * ** ** ** * * **** ** * **** * * * * * * * ** ** * *** endl;
***** * *** *** * ** * 0;

}
最新回答 用戶: (-298 分)
0 喜歡 0 不喜歡
內容已隱藏
#include ** ** *



using *** std;



class Shape

{
* *
** * * * * ** width, height;

public:
***** ***** * * * * ** *** set_data (float a, float b)
* * ** ** ** * **
* ** * * * ** ** * ** * * ** ** ** * ** * = a;
****** * * * *** **** * *** * * ** * * * * = b;
*** ** ** ** ** *** *

};



class ** public Shape

{

public:
* * ** ** *** * ** * area ()
* * * * ** *
* **** ** *** ** *** * ***** * * * *** * * ** * * (width * height);
* *** * * *** * *

};



class ** public Shape

{
** * *
* ** * ** ***** area ()
* * * * ** *** * *
** *** * ****** * *** * ** * * * * * ** * * * * (width * height / 2);
* ** * * ***** * **

};



int main (){
* * ** * ** * * *** * * *
* ********* **** * *** * * rect;
* * * * *** * * ** *** * tri;
* ** ** **** * * ****** * * (5,3);
* *** * ** * ** ** **** * ** * (2,5);
* **** * * * ** ***** * **** **** * ** * * **** ****** ***** * **** * * ** ** * endl;
* *********** * ** ** **** 0;

}
最新回答 用戶: (237 分)
0 喜歡 0 不喜歡
內容已隱藏
*** * * *** * **

using * std;



class * ** *
* * **** *** *** * **
**** ** ** * ** * width;
* *** ** * ** * * * * * height;
* **** ** ** * ** *** * ** * * height);
* * * * * ** * * * area();

};



class * ** *
* *** * * ** * * * ** *
** * * *** * ** * * width;
* ** *** * ** * * **** * height;
* ** * ** * * *** **** * * * height);
** *********** ** ** * * area();

};



void **** :: * ** swidth ,float * * *
* * **** ** * * * = swidth;
****** ** ** * * ** ***** *** = ** *

}



float ** ** :: area(){
*** **** **** * ** ** * ** * *** ** **** ** * *** * (width * ***

}



void * :: * * ** swidth ,float ** ****
** * * ******* **** = swidth;
* * * * ** ** ** * *** = * ***

}



float Triangle :: area(){
** * * * * *** **** ** ***** * ** ** * *** *** *** ((width * *** * *

}



int main (){
* * * ** * ***** * * rect;
* ** * * *** * * * ** * ** tri;
** * **** *** * ** * *** ** (5,3);
* ** * ****** * *** ** * *** * * (2,5);
* * * ** ** ** * * * * * * *** * *** * * * * **** * ** * * ** * * endl;
** * *** * **** ** 0;

}
最新回答 用戶: (-136 分)
0 喜歡 0 不喜歡
內容已隱藏
** **** * ** ** *

using ** std;



class *** *
*** * * * *** * * * **
* **** * ** * ** ** *** * * width;
* ** * *** height;
** ** ** ** *** *** ** ** * * ** height);
* **** * *** ** * ** * * area();

};



class * *
** *** * ** * * * * * * *
** ** ** * * * ** width;
*** * ** * * ** **** * * * * height;
**** *** ** *********** * ********* * ** * **
** ** **** * **** area();

};



void * *** :: **** * * swidth ,float * * *
* *** *** * * ** = swidth;
** * * * **** * ** * = sheight;

}



float * ** :: area(){
** *** * ** *** ** ** * * * **** ** (width * * *

}



void ** * :: * * *** swidth ,float ** *
** ** * * ** * * * ** * ** = swidth;
* *** ***** ***** * ** * = sheight;

}



float Triangle :: area(){
* *** * * * ** *** ** * ***** * *



int main (){
* ** ** * * * ** * ** * rect;
*** * *** ***** * * tri;
*** *** ** ** * ** ** *** *** * ** (5,3);
** * * * *** * * ** *** ** *** (2,5);
* * *** * * ** * * * * ** ** ** *** *** * ** ** * * *** * ** ** ** endl;
* * * ** * * * *** ** 0;

}
最新回答 用戶: (-136 分)
0 喜歡 0 不喜歡
內容已隱藏
*** * * **** * * * *
* ** * **** ****



using namespace std;



class Rectangle{

public:
** * **** *** * ** * ** set_data(int H, int W){
* * * * * *** *** ** * * ** * ** *** *** * = W;
** ** * * ** * * * ** ** ** * ** ** *** * * * = H;
* * * * ****** **** *
*** **** * * **** ****** area(){
* ***** ** *** * ** * ** ** * ****** * ** ** **** **
* ** * ** *** * ** * *



private:
* ** * * * * ****** r_width;
* **** * * * *** ** * * r_height;



};



class Triangle{

public:
** *** ** ** **** * *** ** * set_data(int H, int W){
* * * * ***** **** * * *** * * * * * * = W;
** * * ** *** **** * * **** * ** *** * ** * ** * ** * = H;
***** ** ** *** ** **** ****
* *** * * * **** **** * area(){
* ** **** *** ***** * **** * * * *** **** * * * ***
*** * * ** * *** * ** * *

private:
** * *** * ***** *** ** * t_width;
** ** **** * * * *** * * t_height;

};



int main()

{
**** **** * * * * * ** * rect;
* * ** * *** * *** * * *** tri;
***** ** * * ** ** * ** * ** * (5,3);
*** *** ** * **** **** *** (2,5);
*** * *** ***** ** * ** ** *** ****** rect.area() *** * * * *** * * << tri.area() << endl;
* ** * * * * * * ** * * ** 0;

}
最新回答 用戶: (-368 分)
0 喜歡 0 不喜歡
內容已隱藏
* * * * * * ** * * **



using ** * std;



class * * {
* **** * * * * ** **** width, * **
* * * * ****
*** *** ** *** * * * * * * * *
* *** **** ** * ** ** ** * ** area() * * *

};



void * * *** (int x, int y) {
** * * * * = x;
* ** * **** = y;

}



class * {
*** ** ** * ** ***** * * base, * * **
* * * * * * *
* * ***** * * **** * ** * **
* ** * * * * * * area() {return * ***** *

};



void * ** * (int x, int y) {
* * *** ** *** * = x;
*** ** * * = y;

}



int main (){


* *** * * **** * ** ** * rect;
** * * * *** * * ** * tri;
** **** * ** * * * *** * *** (5,3);
** ** * * ** ** * * *** ** *** (2,5);
** * **** * ***** ** * ** **** * ** *** * * ** * * * ** * ** * * * * ** * endl;
***** * * ** * * * * 0;

}
最新回答 用戶: (-218 分)
0 喜歡 0 不喜歡
內容已隱藏
//

// * * * **

// * **

//

// * * * * * by ** on * *

// * ** * ** © 2017年 *** ** All rights *

//


** * ** ** **
* ** * ***** **

#include ** ** *

using *** * std;



class shape {

public:
*** ** * **** * *** ** * * * width, double height){
** ** **** **** ** ** ***** ** ** * ** * ** * = width;
** *** ** * * **** *** * ** *** * *** * * * = height;
** ** ** **** **** *



public:
* ** ** * * ** * * * * w;
* * ** * * *** ** ** h;

};



class ** public shape{

public:
* * ***** ** * * * ** * ** area(){
******* * * *** ** * ******** * * ** ** ** * * * * ** ***
* ** **** * * * *

};



class * * public shape{

public:
* ** * ** ** * * ** ** * ** * area(){
* ** ** * ** ****** ** * *** ***** **** * * ***** * *
** * ** * * * *

};



int main (){
* * * * ***** **** * * * *
*** ***** * ** * * *** * ** * rect;
* * * * ** *** ** * * tri;
***** ** ** * ***** * * ** ** (5,3);
** ** ** ** * *** * ** * (2,5);
** ** ***** ** ** *** ** * ** * ** * *** * ** * * ** ** * ** * * * * * *** endl;
* ****** *** * *** ** ** 0;

}
最新回答 用戶: (-368 分)
0 喜歡 0 不喜歡
內容已隱藏
*** ** ***** * ***

using ** std;



class ***

{

public:
** * * * * ** ******* * * ****** a,int b);
* *** * **** * ** **** * ** * area();
* *** * ** * ****** a_,b_;

};



void ** *** a,int b)

{
* **** ** ** * * * ****
* * ** ** ** * ** * *

}



int * *

{
* ****** *** * * * * * ***

}





class *

{
***
**** ** * * ** * * * * ** a,int b);
*** * * * ** *** * area();
* ***** * * ** *** ** a_,b_;

};



void **** * * *** a,int b)

{
* ** * * ** ** ** * * * * *
*** ** *** * ****** *** * *

}



int **** * ***

{
* ** * * ** *** * * * * * * a_*b_;

}



int main ()

{
*** ********* * * * ** ** rect;
* * ** * * * ** ** * tri;
* *** * ** * * ** * ** (5,3);
** * * * ** **** * * * ***** ** (2,5);
**** *** * * *** * * * * * * * ** * ** ** ** ** * ** ** ** *** *** * * * *** endl;
*** * * * * * * ** 0;

}
最新回答 用戶: (-324 分)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.175.56
©2016-2025

相關問題

0 喜歡 0 不喜歡
30 回答
[練習] Coding (C) - 最新提問 5月 18, 2017 分類:C++ |
ID: 24769 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 4.1k 瀏覽
0 喜歡 0 不喜歡
17 回答
[練習] Coding (C) - 最新提問 6月 1, 2017 分類:C++ |
ID: 24855 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 2.8k 瀏覽
0 喜歡 0 不喜歡
20 回答
[練習] Coding (C) - 最新提問 4月 27, 2017 分類:C++ |
ID: 24393 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 3.4k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶