Answered step by step
Verified Expert Solution
Link Copied!

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 1) Setting up (This is what I have so far:
#include
#include
#include
#include
using namespace std;
// Function prototype for printing time
void printTime(const char* label, int secs);
int main(int argc, char* argv[]){
if (argc !=2){
cout << "Usage: "<< argv[0]<<""<< endl;
return 0;
}
char* datafile = argv[1];
ifstream infile(datafile);
int runnerCount =0;
while (!infile.eof()){
int minRead =0, secRead =0;
int lapCount =0, totalTime =0;
int fastestTime = INT_MAX, slowestTime = INT_MIN;
int fastestLap =0, slowestLap =0;
cout <<"======"<< endl;
do {
infile >> minRead >> secRead;
if (minR0.5 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 2) Declaring the variables (0.5 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 *60+ 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 3) Writing the loop (0.5 hours)
For this task you will write the loop that reads in the data. As mentioned
elsewhere in these instructions, you should use a do-while loop. We are
starting simple with this task. The body of the do-while 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 do-while 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 do-while 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 "0
0" values.
Task 4) Computing the statistics (1 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 do-while 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 5) Printing the time value (1 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 91, then
that would mean 1 minute and 31 seconds. This would be printed as "01:31".
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.txt.out output file to see the exact expected output.
Task 6) Making a report (1 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 "do-while" 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.txt.out
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions