Special Grading Criteria: You are not permitted to use global variables. No cred
ID: 3864567 • Letter: S
Question
Special Grading Criteria: You are not permitted to use global variables. No credit will be given if global variables are used.
A local running group held a one hour track event where people tried to complete as many miles as they could in one hour. The times were recorded and saved in a file. Each line of the file represents a runner and each line contains 10 entries. The entries are the number of seconds it took to the runner to complete that mile. An entry of zero means the runner didn't finish that mile. You may assume the file will never have more than 20 runners. An example file might look like
Write a program that creates a formatted file that displays the mile times in "minutes:seconds" format and adds an extra column at the end with the average mile time for the runner and an extra column that gives the average mile time for the mile. If the runner didn't complete a mile, the entry should be empty. The above example input would generate the following output
Your solution should have four functions:
The main() function will not be very involved. It will likely consist of the declaration of a handful of variables and then simply calling the import and export functions. Your export function will call toMinutesAndSeconds() Your program should not interact with the user. The input file could have any number of lines, but all lines will contain 10 values.
Explanation / Answer
Here is the solution for above scenario:
#include <stdio.h>
void importData(string filepath, int runnerData[][10], int &runnerCount){
FILE *myfile;
char temp ;
int temp1;
myfile = fopen("filepath","r");
if (myfile== NULL)
{
printf("can not open file ");
return 1;
}
while(line--){
fscanf(myfile,"%s",temp);
temp1 = atoi(temp);
runnerData[i] = temp;
i++;
runnerCount ++;
}
}
void exportTable(string filepath, int runnerData[][10], int runnerCount){
FILE *myfile;
char temp ;
int temp1;
myfile = fopen("filepath","r");
if (myfile== NULL)
{
printf("can not open file ");
return 1;
}
while(line--){
fscanf(myfile,"%s",temp);
temp1 = atoi(temp);
runnerData[i] = temp;
i++;
runnerCount ++;
}
}
int main(void) {
// your code goes here
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.