簡體   English   中英

關於在C ++中創建公式的問題

[英]Question Regarding creating a formula in c++

我認為我的C ++類必須在此分配上缺少某些內容,但我沒有得到它要我們執行的操作。

問題:創建Road類。 該類應具有用於以英尺為單位設置道路寬度和以英里為單位設置道路長度的功能。 它也應該具有獲取道路寬度和道路長度的功能。 請記住,通過提供輸出或獲取輸入,類函數不應與程序用戶交互。 創建一個稱為瀝青的函數,它將接受道路厚度作為輸入參數; 然后根據厚度計算並返回鋪路所需的瀝青立方英尺數(1英里= 5280英尺)。 使用驅動程序全面測試該類的每個功能。

我的問題:我不明白的是,我們應該如何知道要返回的公式以返回所需的立方英尺瀝青量,以及“厚度甚至是”什么單位,我是否在這里遺漏了什么。 任何幫助都會很棒。

我當前的代碼:

#include<iostream>
using namespace std;

class Road
{
private:
int length_miles;
int width_feet;

public:
void set_length(int l)
{
    length_miles = l;
}
void set_width(int w)
{
    width_feet = w;
}

int get_length()
{
    return length_miles;
}
int get_width()
{
    return width_feet;
};

int asphalt(int thickness)
{
    return 1+1; //placeholder forumala
}

};


int main()
{
    Road MainRoad;
    int length;
    int width;
    int thickness;


    cout << "Please enter the length of the road in miles" << endl;
    cin >> length;
    MainRoad.set_length(length);

    cout << "Please enter the width of the road in feet" << endl;
    cin >> width;
    MainRoad.set_width(width);

    cout << "Please enter the thickness of the road in BLANK" << endl;
    cin >> thickness;

    cout << "The amount of asphalt needed for the road is " << MainRoad.asphalt(thickness);

}

我同意@Beta的意見,在沒有必填的厚度單位的情況下,您可以自由選擇自己的厚度。

但是由於方法原型使用int作為厚度的C ++數據類型,並且在我的想象中,瀝青的厚度通常小於1英尺,因此應該使用比英尺更合適的單位。 像英寸或厘米。 由於英寸與班級中使用的其他英制單位更好地匹配,因此我將使用英寸。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM