匿名
匿名 發問於 電腦及互聯網程式編寫及設計 · 9 年前

Programming C/C++高手請入

請問點用Microsoft VISUAL STUDIO C 去做?

我想要code. (見下面ABC 要求)

Aim:

a)practise using printf() statements and print-out (screen) formatting;

b)perform simple calculations using C;

c)practise using branching statement “if-else”.

We are going to implement a Price Comparator for Mobile Phone Users using C. The system liststhe monthly service plans from TWO major Mobile Phone Network Operators. The user theninputs into the system the (integral) number of minutes of air-time he/ she uses this month. Thesystem will calculate and list the related costs under the tariff scheme of the two operators.

/------------------\

| Price Comparator |

\------------------/

Mobile phone network operator monthly plans:

==============================================

Operator: Monthly-air-time in minutes

$Monthly-fee/$Extra-air-time-fee

----------------------------------------------

Banana3: 150 min 600 min 1200 min 4800 min

$38/$2.0 $88/$1.0 $138/$0.5 $288/$0.2

----------------------------------------------

PCCM 2G: 80 min 300 min 800 min 3000 min

$48/$2.2 $58/$1.1 $108/$0.5 $288/$0.3

==============================================

How much air time do you use this month (in integral minutes): <<使用者會入數>>

跟住會彈下面堆野出黎

Costs of joining different operators and different plans

========================================================

Banana3: $2140.00 $ 689.00 $ 138.50 $ 288.00

PCCM 2G: $2514.20 $1049.10 $ 308.50 $ 288.00

A)The first part of the program prints the monthly plans of various operators AS IS.

.

B)The second part of the program asks for the air-time usage information, a single integral number, from the user.

C) The program then calculates and prints the costs under different operators and plans, with 2 decimal places and field width of 7.

更新:

下面回答的人很有心,但我已經試過,好認真的試過,自從B開始,下面既野在我ouput個陣無顯示

只顯示左依d

........

==============================================

How much air time do you use this month (in integral minutes): <<使用者會入數>>

依個接位以下既全部吾出現,又吾比我打數字,吾知點解 但我已好完整寫了個programme>.

更新 2:

可吾可以指點一下個接位應該要寫d咩0.0 佢吾比我打數字 直接彈我

3 個解答

評分
  • 9 年前
    最愛解答

    其實是最基本的programming問題, 強烈建議您自己盡力試做一下。

    A) 頭14行都使用 printf 就可以顯示出來了, 以下做了頭3行給您, 請自行完成其他:

    printf("/------------------\\\n");

    printf("| Price Comparator |\n");

    printf("\\------------------/\n");

    //Do Something Here

    B) 使用scanf問使用者一個整數數字, 請自行查詢一下scanf的用法, 以完成問題:

    printf("How much air time do you use this month (in integral minutes): ");

    int minutes;

    scanf(/*do something here*/);

    C) 使用if-else的方法計算價錢, 例如使用者輸入1201:

    Banan3的150分鐘plan就會是頭150分鐘$38, 餘下每分鐘$2

    即 $38 + (1201 - 150) * $2 = $2140

    以下是計算Banana3的150分鐘計劃的code, 其他的請自行完成:

    double money;

    if (minutes < 150)

    money = 38.0;

    else

    money = 38.0 + (minutes - 150) * 2.0;

    printf("$ %5.2f",money);

    其實要幫您完成整個Program好容易, 根本不用花心機打中文字解釋, 希望您自己嘗試一下完成。

    以下是全段code, 只需完成 do something位置:

    printf("/------------------\\\n");

    printf("| Price Comparator |\n");

    printf("\\------------------/\n");

    //Do Something Here

    printf("How much air time do you use this month (in integral minutes): ");

    int minutes;

    scanf(/*do something here*/);

    printf("Costs of joining different operators and different plans\n");

    printf("========================================================\n");

    double money;

    printf("Banana3: ");

    if (minutes < 150)

    money = 38.0;

    else

    money = 38.0 + (minutes - 150) * 2.0;

    printf("$ %5.2f",money);

    //Do Something Here

    printf("\n");

    printf("PCCM 2G: ");

    if (minutes < 80)

    money = 48.0;

    else

    money = 48.0 + (minutes - 80) * 2.2;

    printf("$ %5.2f",money);

    //Do Something Here

    printf("\n");

    圖片參考:http://icepacific.com/images/yahooknowledge/signat...

  • 9 年前

    #include<stdio.h>

    #include<stdlib.h>

    #define MAX 4

    void show(int b[], float c[], float e[], int mins);

    int main(void)

    {

    int mins = 0; //minutes

    int pccm[MAX] = {80, 300, 800, 3000};

    float pccm_c[MAX] = {48.0, 58.0, 108.0, 288.0};

    float pccm_e[MAX] = {2.2, 1.1, 0.5, 0.3};

    int banana[MAX] = {150, 600, 1200, 4800};

    float banana_c[MAX] = {38.0, 88.0, 138.0, 288.0};

    float banana_e[MAX] = {2.0, 1.0, 0.5, 0.2};

    printf("/------------------\\\n\

    | Price Comparator |\n\

    \\------------------/\n\

    Mobile phone network operator monthly plans:\n\

    ==============================================\n\

    Operator: Monthly-air-time in minutes\n\

    $Monthly-fee/$Extra-air-time-fee\n\

    ----------------------------------------------\n\

    Banana3: 150 min 600 min 1200 min 4800 min\n\

    $38/$2.0 $88/$1.0 $138/$0.5 $288/$0.2\n\

    ----------------------------------------------\n\

    PCCM 2G: 80 min 300 min 800 min 3000 min\n\

    $48/$2.2 $58/$1.1 $108/$0.5 $288/$0.3\n\

    ==============================================\n\

    How much air time do you use this month (in integral minutes):\n");

    scanf("%d",&mins);

    printf("Costs of joining different operators and different plans\n\

    ========================================================\n");

    printf("Banana3: ");

    show(banana, banana_c, banana_e, mins);

    printf("PCCM 2G: ");

    show(pccm, pccm_c, pccm_e, mins);

    system("pause");

    return 0;

    }

    void show(int b[], float c[], float e[], int mins)

    {

    float cost[MAX];

    int i;

    for(i = 0; i < MAX; i++)

    {

    if(mins <= b[i])

    {

    cost[i] = c[i];

    }

    else

    {

    cost[i] = c[i] + (mins - b[i]) * e[i];

    }

    printf("%7.2f", cost[i]);

    }

    printf("\n");

    return;

    }

  • 9 年前

    don't really need 高手....

還有問題嗎?立即提問即可得到解答。