TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

50.0% (1/2)

Tags

Description

函式題,實作函式即可,輸入輸出已經寫好了。題目中使用的code在最下面。(此題請上傳完整的 Code)

定義一個函式 set_box_height_length_breadth ,和定義一個class Box,其包含的成員如下

class Box{
private:
    double length;  // Length  of a box
    double breadth; // Breadth of a box
    double height;  // Height  of a box
public:
    Box() : length(0), breadth(0), height(0){};
    void set_length(double);  // 將 length  設定成傳入的值
    void set_breadth(double); // 將 breadth 設定成傳入的值
    void set_height(double);  // 將 height  設定成傳入的值
    double get_volume();      // 回傳物件的體積
};
// 注意:因為 length、breadth、height是private,只有public的function可以接觸到它。
// 所以你要在set_box_height_length_breadth()裡面,利用參數box呼叫public裡面的function來改變、接觸private裡的變數。
void set_box_height_length_breadth(Box &box, double height, double length, double breadth);

你需要實作5個函式。
. 將 Box 的 length 設定成傳入的值 void set_length(double);
. 將 Box 的 breadth 設定成傳入的值 void set_breadth(double);
. 將 Box 的 height 設定成傳入的值 void set_height(double);
. 回傳物件的體積(宣告在Box內部) double get_volume();
. 設定 Box 的 length, breadth, height (宣告在Box外部) set_box_height_length_breadth(Box &box, double height, double length, double breadth);

Code

#include <iostream>
#include <iomanip>

using namespace std;

class Box{
private:
    double length;  // Length  of a box
    double breadth; // Breadth of a box
    double height;  // Height  of a box
public:
    Box() : length(0), breadth(0), height(0){};
    void set_length(double);  // 將 length  設定成傳入的值
    void set_breadth(double); // 將 breadth 設定成傳入的值
    void set_height(double);  // 將 height  設定成傳入的值
    double get_volume();      // 回傳物件的體積
};

// 注意:因為 length、breadth、height是private,只有public的function可以接觸到它。
// 所以你要在set_box_height_length_breadth()裡面,利用參數box呼叫public裡面的function來改變、接觸private裡的變數。
void set_box_height_length_breadth(Box &box, double height, double length, double breadth);

/******************************/
/* Your code will be put here */





/******************************/

int main(){

    Box box1; // Declare Box1 of type Box

    double height, length, breadth;
    cin >> height >> length >> breadth;

    set_box_height_length_breadth(box1, height, length, breadth);

    cout << "Volume of Box1 : " << setprecision(2) << fixed << box1.get_volume() << endl;

    return 0;
}

Input Format

輸入三個浮點數代表長、寬、高。

Output Format

輸出體積,並換行。體積=長 * 寬 * 高。

保證不溢位

輸出補充:
testdata 1~3 分別代表 範測1~3
可以用這幾項來確定輸出格式是否正確

Sample Input 1

5.0 6.0 7.0

Sample Output 1

Volume of Box1 : 210.00

Sample Input 2

61.89 56.15 44.60

Sample Output 2

Volume of Box1 : 154990.51

Sample Input 3

16.83 36.67 38.93

Sample Output 3

Volume of Box1 : 24025.89

Hints

Problem Source

NEOJ Problem 596

Subtasks

No. Testdata Range Constraints Score
1 0 0
2 1 0
3 2 0
4 3~29 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 2
2 1000 65536 65536 3
3 1000 65536 65536 4
4 1000 65536 65536 4
5 1000 65536 65536 4
6 1000 65536 65536 4
7 1000 65536 65536 4
8 1000 65536 65536 4
9 1000 65536 65536 4
10 1000 65536 65536 4
11 1000 65536 65536 4
12 1000 65536 65536 4
13 1000 65536 65536 4
14 1000 65536 65536 4
15 1000 65536 65536 4
16 1000 65536 65536 4
17 1000 65536 65536 4
18 1000 65536 65536 4
19 1000 65536 65536 4
20 1000 65536 65536 4
21 1000 65536 65536 4
22 1000 65536 65536 4
23 1000 65536 65536 4
24 1000 65536 65536 4
25 1000 65536 65536 4
26 1000 65536 65536 4
27 1000 65536 65536 4
28 1000 65536 65536 4
29 1000 65536 65536 4