Question: In this question you will implement a C++ program that will read an unsorted file into a vector of a struct, sort it and print

 In this question you will implement a C++ program that willread an unsorted file into a vector of a struct, sort it

In this question you will implement a C++ program that will read an unsorted file into a vector of a struct, sort it and print it onto the console. You will develop the entire program, including the struct, #include statements and the main() function. The program will read a file named "raceresults.txt, which contains the results of a car race, however the ordering is wrong. On each line of the file you will find the car number, the name and surname of the driver and total time it took that driver to finish the race. On each line there will be exactly one (1) name and exactly one (1) surname. Sample raceresults.txt 5 Sebastian Vettel 1234.5 33 Max Verstappen 1243.2 44 Lewis Hamilton 1230.9 . Firstly, you should create the struct called result . This struct will store the name, the car number and the finishing time of each driver in the txt file. Your program should open and read the file raceresults.txt line-by-line (you may assume the file always exists and can avoid checking .fail() ). All of this information should be stored in a vector of the result type. Once all lines are read, your program should sort this vector based on the finishing times of the drivers. After your program has sorted the vector it must print out the results onto the console based on the time differences of the drivers. You must create a function called printResults and output the result from this function. On each line on the console your program should print out the position, the name, the car number, the time difference to the leader and the time difference to the nearest opponent that has finished the race one position ahead: 1. Lewis Hamilton (#44) WINNER 2. Sebastian Vettel (#5) +3.6 (+3.6) 3. Max Verstappen (#33) +12.3 (+8.7) Sample Run Input raceresults.txt 77 Valtteri Bottas 1210.224 44 Lewis Hamilton 1202.319 11 Sergio Perez 1230.139 16 Charles Leclerc 1220.282 1 Max Verstappen 1190.996 Console output of the program: 1. Max Verstappen (#1) WINNER 2. Lewis Hamilton (#44) +11.323 (+11.323) 3. Valtteri Bottas (#77) +19.228 (+7.905) 4. Charles Leclerc (#16) +29.286 (+10.058) 5. Sergio Perez (#11) +39.143 (+9.857) As you can see from the sample run, the winner car will not display any time differences, because there is nothing to display. Hence, your program should output WINNER next to the winning driver name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!