Code:/* Preprocessor directives */ #include <stdio.h> #include <math.h> #define input_file "c:\\engr 200\\train.txt" #define output_file "c:\\engr 200\\train_report.txt" /* Define the structure to represent a tsunami */ struct trains { double time, displace, velocity; }; /* Main Function */ int main(void) { /* Declare and initialize variables */ struct trains tr[51]; int nrows,ncols, i, j; double displace, velocity, time; FILE *train, *train_report; /* Open input file */ train = fopen(input_file,"r"); train_report = fopen(output_file,"w"); /* Verify input file, read control number, and hurricane data */ if(train == NULL) { printf("\n\n\n\n ERROR OPENING INPUT FILE."); printf("\n\n PROGRAM TERMINATED.\n\n\n"); return 0; } else { /* Read control number */ fscanf(train,"%i %i",&nrows,&ncols); /* Read train data into array */ for(j=0; j<=ncols-1; j++) { for(i=0; i<=nrows-1; i++) { fscanf(train,"%lf %lf %lf",&tr[i].time, &tr[i].displace, &tr[i].velocity); } } } /* calculations */ for(i=0; i<=nrows-1; i++) { for(j=0; j<=ncols-1; j++) { tr[i].displace = 4.219*(exp(-1.58*time)-exp(-6.32*time)); tr[i].velocity = 26.67*exp(-6.32*time)-6.67*exp(-1.58*time); } } /* Print headings */ printf("************ START REPORT ***********" "\n\n TRAIN CAR STOPPING ANALYSIS" "\n\n\n Time Displacement Velocity" "\n (s) (m) (m/s)"); fprintf(train_report,"************ START REPORT ***********" "\n\n TRAIN CAR STOPPING ANALYSIS" "\n\n\n Time Displacement Velocity" "\n (s) (m) (m/s)"); /* Print array */ for(i=0; i<=nrows-1; i++) for(j=0; j<=ncols-1; j++) { printf("\n%6.3f %6.3f %6.3f",tr[i].time, tr[i].displace,tr[i].velocity); fprintf(train_report,"\n%6.3f %6.3f %6.3f",tr[i].time, tr[i].displace,tr[i].velocity); } /* Print end */ printf("\n\n************ END REPORT *************\n\n\n"); fprintf(train_report,"\n\n************ END REPORT *************\n\n\n"); /* Close the input file */ fclose(train); fclose(train_report); /* Exit the program */ return 0; } /******************************************************************************/