Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you write the code for the input? (40 points) Write a program that calculate

ID: 3880967 • Letter: C

Question

Can you write the code for the input?

(40 points) Write a program that calculates the distance a car travels based on the time and speed provided in a file. This program should use the parallel arrays in the main function provided and follow the specifications a-d below. 2. const int SIZE 5; int main 0 int time[SIZE]; int speed [SIZE] int distance [SIZE]; load_arrays (time, speed); calculate dist (time, speed, distance); print (time, speed, distance); a) b) c) Write a function that will open an input file, gets the time and speed from a file and store them in the respective arrays. The format of the file is 2 integer values separated by a space on each line Write a function that will calculate the distance from the values in the time and speed arrays and place the answer in the distance array. Write a function that will print out the input data from a) and the calculated items from b) above (print the file data to the screen, and the calculated distance values in the format of 3 items on one

Explanation / Answer

The three function according to the specifications are given below

void load_arrays(int time[],int speed[])
{
FILE *f =fopen("input.txt","r");
int t,s,i;
for(i=0;i<SIZE;i++)
{
fscanf(f,"%d %d",&t,&s);
time[i]=t;
speed[i]=s;
}
}
void calculate_dist(int time[],int speed[],int distance[])
{
int i;
for(i=0;i<SIZE;i++)
{
distance[i]=time[i]*speed[i];
}
}
void print(int time[],int speed[],int distance[])
{
int i;
for(i=0;i<SIZE;i++)
{
printf("Time = %d, Speed = %d, Distance = %d ",time[i],speed[i],distance[i]);
}
}

Do give a thumbs up. Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote