/* 20060301.cpp  データをキーボードから入力して1区間の処理を行う */

 

#include<stdio.h>

 

const char memo_A[46] ="gensoku tochu 120km/h 30s, 45km/h 30s soukou.";

const char memo_B[33] ="gensoku tochu 45km/h 30s soukou.";

float kasokudo  = (float)1.8;// [km/h/s]

float gensokudo = (float)1.5;// [km/h/s]

float ekikan_kyori  =0.0;// [km]:input

float seigen_sokudo =0.0;// [km/h]:input

float kasoku_jikan  =0.0;// [s]

float kasoku_kyori  =0.0;// [km]

float gensoku_jikan =0.0;// [s]

float gensoku_kyori =0.0;// [km]

float junkou_jikan  =0.0;// [s]

float junkou_sokudo =0.0;// [km/h]

FILE *fp;   // 結果出力用のファイル

         

int main(){

        void  input_output(void);

        float junkou_sokudo_kettei(float);

        void  kasoku_output(void);

        void  gensoku_output(void);

        void  junkou_output(void);

        void  ekikan_output(void);

 

        fp  = fopen("20060311w.dat","w");

        input_output();

        junkou_sokudo = junkou_sokudo_kettei(ekikan_kyori);

        if(junkou_sokudo > seigen_sokudo)junkou_sokudo=seigen_sokudo;

    kasoku_output();

        gensoku_output();

        junkou_output();

        ekikan_output();

    fclose(fp);

        return(1);

}

 

void input_output(){

        char  c=' ';

        char  eki_from[20]="                   ";

        char  eki_to[20]  ="                   ";

 

    printf("kasokudo  = ?.? [km/h/s] :");

        scanf("%f",&kasokudo);

        printf("gensokudo = ?.? [km/h/s] :");

        scanf("%f",&gensokudo);

        printf("Hatsu Eki = ????????? :");

        c = getchar();

        int k=0;

        c = getchar();

        while(c!='\n'){

                eki_from[k] = c;

                c = getchar();

                k++;

        }

        printf("Cyaku Eki = ????????? :");

        k=0;

        c= getchar();

        while(c!='\n'){

                eki_to[k] = c;

                c = getchar();

                k++;

        }

        printf("Ekikan Kyori  = ?.? [km] :");

        scanf ("%f",&ekikan_kyori);

        printf("Seigen Sokudo = ?.? [km/h] :");

        scanf ("%f",&seigen_sokudo);

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

        printf("FROM  %20s  TO  %20s       \n\n", eki_from, eki_to);

        printf("EKIKAN KYORI  = %5.1f[km]  \n\n", ekikan_kyori    );

        printf("SEIGEN SOKUDO = %5.1f[km/h]\n\n", seigen_sokudo   );

        fprintf(fp,"FROM  %20s  TO  %20s       \n\n", eki_from, eki_to);

    fprintf(fp,"EKIKAN KYORI  = %5.1f[km]  \n\n", ekikan_kyori    );

        fprintf(fp,"SEIGEN SOKUDO = %5.1f[km/h]\n\n", seigen_sokudo   );

}

 

float junkou_sokudo_kettei(float kyori){

        float sokudo=1.0;

        if     (kyori>=40.0)sokudo=300.0;

        else if(kyori>=35.0)sokudo=280.0;

        else if(kyori>=30.0)sokudo=260.0;

        else if(kyori>=25.0)sokudo=240.0;

        else if(kyori>=20.0)sokudo=220.0;

        else if(kyori>=15.0)sokudo=200.0;

    else if(kyori>=10.0)sokudo=180.0;

        else if(kyori>= 6.0)sokudo=160.0;

        else if(kyori>= 4.0)sokudo=140.0;

        else if(kyori>= 3.0)sokudo=120.0;

        else if(kyori>= 2.0)sokudo=100.0;

        else if(kyori>= 1.5)sokudo= 80.0;

        else if(kyori>= 1.0)sokudo= 60.0;

        else if(kyori>= 0.5)sokudo= 45.0;

    else printf("kyori error");

    return(sokudo);

}

 

void kasoku_output(){

        int kasoku_jikan_m =0;

        int kasoku_jikan_s =0;

       

        kasoku_jikan   = junkou_sokudo / kasokudo;

        kasoku_jikan_m = (long)kasoku_jikan / 60;

        kasoku_jikan_s = (long)kasoku_jikan % 60;

        kasoku_kyori   = (junkou_sokudo / (float)2.0) * (kasoku_jikan / (float)3600.0);

   

        printf("KASOKU   :  %3.1f[km/h/s],", kasokudo);

        printf(" %3d[m] %2d[s],", kasoku_jikan_m, kasoku_jikan_s);

        printf(" %5.1f[km] \n\n", kasoku_kyori);

    fprintf(fp,"KASOKU   :  %3.1f[km/h/s],", kasokudo);

        fprintf(fp," %3d[m] %2d[s],", kasoku_jikan_m, kasoku_jikan_s);

        fprintf(fp," %5.1f[km] \n\n", kasoku_kyori);

}

 

void gensoku_output(){

    float gensoku_jikan_A =0.0;

        int   gensoku_jikan_m =0;

        int   gensoku_jikan_s =0;

 

        gensoku_jikan_A = junkou_sokudo / gensokudo;

        if(junkou_sokudo > 120){

                gensoku_jikan = gensoku_jikan_A + (float)60.0;

                gensoku_kyori = (junkou_sokudo / (float)2.0) * (gensoku_jikan_A / (float)3600.0) + (float)1.375;

                printf("%46s\n\n", memo_A);

                fprintf(fp,"%46s\n\n", memo_A);

        }

        else if(junkou_sokudo > 45){

                gensoku_jikan = gensoku_jikan_A + (float)30.0;

                gensoku_kyori = (junkou_sokudo / (float)2.0) * (gensoku_jikan_A / (float)3600.0) + (float)0.375;

                printf("%33s\n\n", memo_B);

                fprintf(fp,"%33s\n\n", memo_B);

        }

        else{

                gensoku_jikan = gensoku_jikan_A;

                gensoku_kyori = (junkou_sokudo / (float)2.0) * (gensoku_jikan_A / (float)3600.0);

        }

        gensoku_jikan_m = (long)gensoku_jikan / 60;

        gensoku_jikan_s = (long)gensoku_jikan % 60;

        printf("GENSOKU  :  %3.1f[km/h/s],", gensokudo);

        printf(" %3d[m] %2d[s],", gensoku_jikan_m, gensoku_jikan_s);

        printf(" %5.1f[km]\n\n", gensoku_kyori);

        fprintf(fp,"GENSOKU  :  %3.1f[km/h/s],", gensokudo);

        fprintf(fp," %3d[m] %2d[s],", gensoku_jikan_m, gensoku_jikan_s);

        fprintf(fp," %5.1%f[km]\n\n", gensoku_kyori);

}

 

void junkou_output(){

        float junkou_kyori = 0.0;

        int  junkou_jikan_m = 0;

        int  junkou_jikan_s = 0;

 

        junkou_kyori = ekikan_kyori - kasoku_kyori - gensoku_kyori;

        junkou_jikan = (junkou_kyori / junkou_sokudo) * (float)3600.0;

        junkou_jikan_m = (long)junkou_jikan / 60;

        junkou_jikan_s = (long)junkou_jikan % 60;

        printf("JUNKOU   :  %5.1f[km/h],", junkou_sokudo);

        printf(" %3d[m] %2d[s],", junkou_jikan_m, junkou_jikan_s);

        printf(" %5.1f[km]\n\n", junkou_kyori);

        fprintf(fp,"JUNKOU   :  %5.1f[km/h],", junkou_sokudo);

        fprintf(fp," %3d[m] %2d[s],", junkou_jikan_m, junkou_jikan_s);

        fprintf(fp," %5.1f[km]\n\n", junkou_kyori);

}

 

void ekikan_output(){

        float ekikan_jikan  = 0.0;

        float heikin_sokudo = 0.0;

        int   ekikan_jikan_m = 0;

        int   ekikan_jikan_s = 0;

 

        ekikan_jikan = kasoku_jikan + gensoku_jikan + junkou_jikan;

        ekikan_jikan_m = (long)ekikan_jikan / 60;

        ekikan_jikan_s = (long)ekikan_jikan % 60;

        heikin_sokudo = ekikan_kyori / (ekikan_jikan / (float)3600.0);

        printf("HEIKIN SOKUDO = %5.1f[km/h]\n\n",heikin_sokudo);

        printf("EKIKAN JIKAN  = %3d[m] %2d[s]\n\n", ekikan_jikan_m, ekikan_jikan_s);

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

    fprintf(fp,"HEIKIN SOKUDO = %5.1f[km/h]\n\n",heikin_sokudo);

        fprintf(fp,"EKIKAN JIKAN  = %3d[m] %2d[s]\n\n", ekikan_jikan_m, ekikan_jikan_s);

}