Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT!! NEED HELP!!Task 1 ) Setting up ( 0 . 5 hours ) Open the splits.cpp file and read through the code. There are comments
URGENT!! NEED HELP!!Task Setting up 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. 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 minRead secRead
Calculate actual seconds
int actualSeconds minRead secRead;
Update lap count and total time
lapCount;
totalTime actualSeconds;
Update fastest and slowest lap details
if actualSeconds fastestTime
fastestTime actualSeconds;
fastestLap lapCount;
if actualSeconds slowestTime
slowestTime actualSeconds;
slowestLap lapCount;
while minRead secRead ;
Calculate average lap time
int averageTime lapCount totalTime lapCount : ;
Print report
cout "Total laps: lapCount endl;
cout "Total time: ;
printTime totalTime;
cout "Average lap time: ;
printTime averageTime;
cout "Fastest lap was # fastestLap endl;
cout "Fastest Lap Time: ;
printTime fastestTime;
cout "Slowest lap was # slowestLap endl;
cout "Slowest Lap Time: ;
printTime slowestTime;
cout endl;
runnerCount;
infile.close;
return ;
Function definition for printing time
void printTimeconst char label, int secs
int minutes secs ;
int seconds secs ;
cout setfill setw minutes : setw seconds endl;
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