I need help creating this program. I can\'t get the file to work correctly. The
ID: 3550578 • Letter: I
Question
I need help creating this program. I can't get the file to work correctly.
The distance that a car (undergoing constant acceleration) will travel is given by the expression S = V0 t + 1/2 at 2 where s = distance travelled V0 = initial velocity t = time of travel a = acceleration Write a program that computes this distance given V0, t, and a. The Basics of C The input should come from the file DISTANCE.DAT with the following format: line 1 V0 t line 2 a1 line 3 a2 line 4 a3 line 5 a4 line 6 a5 line 7 v0 line 8 a1 line 9 a2 line 10 a3 line 11 a4 line 12 a5 All the above numbers are real numbers. An example data file is 10 5 3 4 5 6 7 10 10 3 4 5 6 7 Print the results to the file DISTANCE.OUT in the lowing form: lowing form: car under constant accelerationExplanation / Answer
SourceCode: http://kopasite.net/up/i5123rndlrgm1r9/velocity.c
SampleInput: http://kopasite.net/up/fpem992erd6b46w/DISTANCE.DAT
Output: http://kopasite.net/up/74wn9x6zs1v4756/DISTANCE.OUT
#include<stdio.h>
int main()
{
double V_0,t,a,S;
int i;
FILE *in_fp,*out_fp;
in_fp = fopen("DISTANCE.DAT","r");
out_fp = fopen("DISTANCE.OUT","w");
fprintf(out_fp,"Car under constant acceleration ");
fprintf(out_fp,"Initial velocity time acceleration Distance ");
fprintf(out_fp,"---------------- ---- ------------ -------- ");
while(1)
{
if(fscanf(in_fp,"%lf %lf",&V_0,&t)!=EOF)
{
for(i=0;i<5;i++)
{
fscanf(in_fp,"%lf",&a);
S = V_0*t + 0.5*a*t*t;
fprintf(out_fp,"%16.2lf %4.2lf %12.2lf %8.2lf ",V_0,t,a,S);
}
}
else
{
break;
}
}
fclose(in_fp);
fclose(out_fp);
return 0;
}
If you have any questions, please let me know in the comments.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.