1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
DESCRIPTION OF VARIABLES:
NAME | TYPE | DESCRIPTION
|
seconds | double | one-dimensional array of time data in seconds
displacement | double | computed horizontal displacement in meters
velocity | double | computed velocity in meters per second
i | int | "for" loop index variable
ndata | int | number of time data inputs
***********************************************************************/
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "c:\\users\\billy\\desktop\\engr 200\\time.txt"
#define outputfile "c:\\users\\billy\\desktop\\engr 200\\bumper.txt"
/* Main function */
int main(void)
{
/* Declare and initialize variables */
double seconds[51], displacement[51], velocity[51];
int i, ndata;
FILE *report, *table;
/* Open input and output files */
report = fopen(inputfile,"r");
table = fopen(outputfile,"w");
/* Verify input file, quit if empty, else read input data */
if(report == NULL)
{
printf("\n\nError opening input file.");
printf("\nProgram terminated.");
printf("\n\n\nPress Enter to quit.\n");
getchar(); getchar();
return 0;
}
else
{
/* Read control number */
fscanf(report,"%i",&ndata);
/* Read input data into array */
for(i=0; i<=ndata-1; i++)
fscanf(report,"%lf",&seconds[i]);
}
/* Compute the horizontal displacement and velocity */
for(i=0; i<=ndata-1; i++)
{
displacement[i] = 4.219 * (exp(-1.58*seconds[i]) - exp(-6.32*seconds[i]));
velocity[i] = (26.67 * exp(-6.32*seconds[i])) -
(6.67 * exp(-1.58*seconds[i]));
}
/* Print report to computer screen and output file */
printf("******************************************"
"\n STOPPING ANALYSIS"
"\n\n Time Displacement Velocity"
"\n(seconds) (meters) (meters/sec)");
fprintf(table,"******************************************"
"\n STOPPING ANALYSIS"
"\n\n Time Displacement Velocity"
"\n(seconds) (meters) (meters/sec)");
for(i=0; i<=ndata-1; i++)
{
printf("\n %4.2f %5.3f %6.3f",
seconds[i],displacement[i],velocity[i]);
fprintf(table,"\n %4.2f %5.3f %6.3f",
seconds[i],displacement[i],velocity[i]);
}
printf("\n******************************************");
fprintf(table,"\n******************************************");
/* Close input and output files */
fclose(report);
fclose(table);
/* Exit program */
printf("\n\n\nPress Enter to quit.\n");
getchar(); getchar();
return 0;
}
/*********************************************************************/ |