Answered step by step
Verified Expert Solution
Link Copied!

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 1) Setting up (0.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. 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 (minRead !=0|| secRead !=0){
// Calculate actual seconds
int actualSeconds = minRead *60+ 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 !=0|| secRead !=0);
// Calculate average lap time
int averageTime = lapCount !=0? totalTime / lapCount : 0;
// 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 0;
}
// Function definition for printing time
void printTime(const char* label, int secs){
int minutes = secs /60;
int seconds = secs %60;
cout << setfill('0')<< setw(2)<< minutes <<":"<< setw(2)<< seconds << endl;
}

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

Step: 3

blur-text-image

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

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago