Question
A few people are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into
A few people are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the end of the week, they would like to know the number of miles run each day, the total number of miles for the week, and average miles each day. Write a program to help them analyze their data. Your program will contain the following custom type to store the runner info.
struct runnerType { string name ; int milesPerDay [7]; int totalMiles ; double average ; };
And in your main, you will create an array of runnerType, and its size will be 50. You will write the following functions: void readRunnerData(runnerType runnerArray[], int& numRunners, ifstream& in) is a function that takes in an array of runnerType, the numRunners counter, and the input filestream in, this will populate the runnerArray with the items in the file, and numRunners value is incremented after every successful line that was read int totalMilesRan(int miles[]) is a function that takes in an array of miles ran each day and the sum of those miles is returned double averageMilesPerDay(int miles[]) is a function that takes in an array of miles ran each day and returns the average miles ran per day void bubbleSort(runnerType runnerArray[], int numRunners) is a function that will sort runnerArray by name (in ascending order) and takes in the numRunners counter once again to know how many elements to sort void outputResults(runnerType runnerArray[], int numRunners) is a function that will output everything in the runnerArray nicely formatted.
Inside your main, you will prompt the user for an input filename, if that file does not exist, you will keep re-prompting until a filename that can actually be opened and read from the command line. Then 1 you will call the readRunnerData function to populate the array, then you will call totalMilesRan and averageMilesPerDay to populate the rest of the fields of the struct. Then you will call bubbleSort to sort the array, and finally call outputResults which will nicely output everything and find the runner with the max number of miles and the min average. I posted a main file with some of the code worked out to help you get started, its on the moodle site in the same location as where this pdf is posted.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started