C++改寫副程式

// filename: 99551234_3.cpp (30)

// purpose: 改寫下列程式以副程式()方式呼叫

#include <stdio.h>

#include <stdlib.h>

int sel1;

float temp, A, B, C, D;

double bmi, n_h, height, weight;

float result;

float func1(float Ctemp);

float func1(float Ctemp)

{ return (160.0+9*Ctemp)/5.0;

}

void func2()

{ printf("華氏溫度:");

scanf("%f",&temp);

printf("攝氏溫度為%.2f\n",(temp-32)*5/9);

}

void func3()

{ printf("計算(A+Bi)*(C+Di)\n");

printf("<#輸入 A,B,C,D 各值>: ");

scanf("%f %f %f %f",&A, &B, &C, &D);

printf("(A+Bi)*(C+Di)=%.4f+%-.4fi\n",A*C-B*D, A*D+B*C);

}

void func4()

{ printf("height= ");

scanf("%lf",&height);

printf("weight= ");

scanf("%lf",&weight);

n_h = height/100.0;

bmi = weight / (n_h*n_h);

printf("your BMI is %lf\n", bmi);

}

int main(){

do {

printf("menu choice\n");

printf("[1]C to F\t[2]F to C\t[3]complex MUL \t[4] BMI calculation \t[9]Quit\n");

scanf("%d",&sel1);

switch(sel1){

case 1:

printf("攝氏溫度:");

scanf("%f",&temp);

result=func1(temp);

printf("華氏溫度為%.2f\n",result);

break;

case 2:

func2();

break;

case 3:

func3();

break;

case 4:

func4();

default: ;

}

} while(sel1!=9);

system("pause");

return 0;

}//int main() 的下刮弧

怎麼用副程式改寫呢?

2 Answers

Rating
  • 1 decade ago
    Favorite Answer

    // filename: 99551234_3.cpp (30)

    // purpose: 改寫下列程式以副程式()方式呼叫

    #include <stdio.h>

    #include <stdlib.h>

    int sel1;

    float temp, A, B, C, D;

    double bmi, n_h, height, weight;

    float result;

    float func1(float Ctemp)

    {

    return (160.0+9*Ctemp)/5.0;

    }

    void func2()

    {

    printf(”華氏溫度:”);

    scanf(”%f”,&temp);

    printf(”攝氏溫度為%.2f&#92;n”,(temp-32)*5/9);

    }

    void func3()

    {

    printf(”計算(A+Bi)*(C+Di)&#92;n”);

    printf(”<#輸入 A,B,C,D 各值>: ”);

    scanf(”%f %f %f %f”,&A, &B, &C, &D);

    printf(”(A+Bi)*(C+Di)=%.4f+%-.4fi&#92;n”,A*C-B*D, A*D+B*C);

    }

    void func4()

    {

    printf(”height= ”);

    scanf(”%lf”,&height);

    printf(”weight= ”);

    scanf(”%lf”,&weight);

    n_h = height/100.0;

    bmi = weight / (n_h*n_h);

    printf(”your BMI is %lf&#92;n”, bmi);

    }

    int main_func()

    {

    system(”cls”);

    printf(”menu choice&#92;n”);

    printf(”[1]C to F&#92;t[2]F to C&#92;t[3]complex MUL &#92;t[4] BMI calculation &#92;t[9]Quit&#92;n”);

    scanf(”%d”,&sel1);

    switch(sel1)

    {

    case 1:

    printf(”攝氏溫度:”);

    scanf(”%f”,&temp);

    result=func1(temp);

    printf(”華氏溫度為%.2f&#92;n”,result);

    break;

    case 2:

    func2();

    break;

    case 3:

    func3();

    break;

    case 4:

    func4();

    }

    return sel1;

    }

    int main()

    {

    do {

    }while(main_func()!=9);

    system(”pause”);

    }

    //int main() 的下刮弧 怎麼用副程式改寫呢?

    2008-06-27 13:02:03 補充:

    我有把一些會出問題的字改成全形

    像 '<' , '>' , '"'

    可是我反斜線忘了改

    就變成了&#92;這種東西

    你可以善用記事本的取代功能喔

    2008-06-28 20:40:43 補充:

    我不是已經用副程式寫了嗎

    你是不太滿意嗎??

  • 1 decade ago

    現在已經是用副程式寫了

Still have questions? Get your answers by asking now.