Question: main.cpp The main program logic should do the following: Check for the correct number of command line arguments ( 2 or 3 ) . Print
main.cpp
The main program logic should do the following:
Check for the correct number of command line arguments or Print a usage message and return if the number is incorrect
Initialize an empty scoreboardlinked list by declaring the head Node
Read the scoreboard from the first file and add each climber to the list using the insertsorted function
If a second file is provided:
Repeat the previous two steps to create a second scoreboard, thenCreate a new list with the combined scores from each category summing the scores together
Display either or scoreboards to the console, sorted by score
The scoreboards should be presented as shown in The Program sectionTo know which file is being read to print the appropriate title Bouldering or Lead results you can use strstr from the library to check if the filename contains bouldering or leadthe files will always have the words bouldering or lead in them
Finally, clean up any memory that was allocated
For both files, make sure that the file can be opened; if not, display an error message and return.
You may find it useful to define helper functions for the repeated steps in this process, but as usual, your main.cpp will not be considered by the unit tests.
climber.h and climber.cpp
The Climber structure is provided in climber.h while you will need to implement readwrite functions in climber.cpp The Climber struct is defined as follows:
struct Climber char name; char country; double score; ;
The read function should read a single row from the CSV into a Climber object, while the write function should display the climbers info formatted for human readability as shown in the output formatting section. Do not print the rank from this function your Climber object should have no idea what position it occupies in the list.
Notice also that read returns an istream& instead of void. This is so that you can chain multiple reads together, and use the read function in a while loop, eg:
Climber c; while readin c
Tests for the read and write functions are provided in teststestacpp
scoreboard.h and scoreboard.cpp
This is where most of the magic happens: your linked list. scoreboard.h defines a Node structure as well as a set of public functions:
insertsorted: Inserts a climber into the list, keeping the list sorted by score. Assume that scores are unique. If the climber already exists in the list, do not insert it again.
find: finds a climber by name in the list and returns a pointer to the Climber. If the climber is not found, return nullptr.
clear: empties the list and frees all the memory
Note: the clear function is not declared in the header. I would like you to declare and implement this function to practice choosing an appropriate function signature.
write: writes the list to an output stream, formatted as in the output formatting section. Youll need to write out the header, then iterate through the list and keep track of the rank position in the list printing out the rank and calling the writefunction for each Climber.
For each of these functions, dont forget to consider edge cases, such as:
Is the list empty head nullptr
Does the head need to be updated either removing the head, or inserting before the head
Is the list a singleton head is the only node
Are you adding or removing at the end of the list?
Feel free to implement private helper functions as desired to keep the logic straight.
Simplifying Assumptions
The scores are unique, so you dont need to worry about two climbers having the same score If two climbers have the same score, they can be displayed in any order.
The country code is always exactly characters long.
The files will always have the word bouldering or lead in them such as mensbouldering.csv or womenslead.csv
The files will always be formatted as given in the example, with no extra whitespace around the commas or empty lines.
The linked list implementation is not complete eg no remove function but it provides all the functionality needed to complete this assignment.
Two files
When the program is run with both the bouldering and lead datafiles, it should display the following:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
