Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 ) Setting up ( This is what I have so far: #include #include #include #include using namespace std; / / Function prototype for
Task Setting up This is what I have so far:
#include
#include
#include
#include
using namespace std;
Function prototype for printing time
void printTimeconst char label, int secs;
int mainint argc, char argv
if argc
cout "Usage: argv endl;
return ;
char datafile argv;
ifstream infiledatafile;
int runnerCount ;
while infile.eof
int minRead secRead ;
int lapCount totalTime ;
int fastestTime INTMAX, slowestTime INTMIN;
int fastestLap slowestLap ;
cout endl;
do
infile minRead secRead;
if minR hours
Open the splits.cpp file and read through the code. There are comments that explain what is happening in my part of the code
and comments that explain what you will need to do
Task Declaring the variables hours
For this task, You are not going to write the whole program. Instead, you are
just going to declare the variables that you're going to need and put them in
the right place in the file.
You will need several variables:
a variable to hold the minutes value when you read it
a variable to hold the seconds value when you read it
a variable to track the lap count
a variable to sum the total time
variables to keep track of the fastest time and fastest lap number
variables to keep track of the slowest time and slowest lap number
Since we are reading in data in terms of minutes and seconds and those values
are not the easiest for doing math with, we will convert each time into
seconds using the formula:
actualSeconds minutesRead secondsRead
You will need a variable to hold this calculated value so that also needs to
be declared.
All these variables should be declared inside the outer "while" loop the one
that I already provided This is so that each time through this outer loop,
the variables are reinitialized. This is necessary to support reading multiple
sets of data.
Task Writing the loop hours
For this task you will write the loop that reads in the data. As mentioned
elsewhere in these instructions, you should use a dowhile loop. We are
starting simple with this task. The body of the dowhile loop should simply
read the minutes and seconds into some of the variables that you declared
above and then calculate the actual seconds.
For the purposes of debugging, add statements to your dowhile loop body to
print out the values that you read and computed. These lines of output will
not be in the final program but they are a good stepping stone towards getting
there.
Finally, set up the proper condition for exiting the dowhile loop.
When this is done you should be able to compile and run the program. When you
run it you should see the values from the data file being printed on the
screen. Make sure that you are getting all the values and not getting the
values.
Task Computing the statistics hour
The project requirements are that you keep track of the number of laps, the
fastest lap time, the fastest lap number, the slowest lap time, and the
slowest lap number.
Add the code inside your dowhile loop to update all these values. Note that
using the actual seconds for the comparisons will make things much simpler.
You should be able to compile and run your program. Since you haven't added
any new output, nothing should change.
Task Printing the time value hour
For this task you will implement the code in the printTime function that
exists in splits.cpp Notice that this function takes two arguments: "label",
"secs". The "label" is a string that should be printed before the time
value. The "secs" is the number of seconds. For example, if "secs" is then
that would mean minute and seconds. This would be printed as :
The project requirements are that both the MM and the SS fields are always two
digits. Also, the requirements are that you use setw and setfill to get this
format.
Look at the data.txtout output file to see the exact expected output.
Task Making a report hour
Now that you have the printTime function working, you can complete the
program. After all the data for a single runner has been read, you need to
print a report that includes the total time, the total laps, the average lap
time, the fastest lap number, the fastest lap time, the slowest lap number,
and the slowest lap time.
Since this is after all the data for a single runner has finished, this code
should be after your dowhile" loop. Since there may be other runners' data
still in the file, it must be inside the outer "while" loop that I provided
Use the printTime function to generate the output. Look at the data.txtout
output file to see the exact expected output. this is what i have so far:
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