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 (2 or 3). Print a usage message and return if the number is incorrect
Initialize an empty scoreboard(linked list) by declaring the head Node *.
Read the scoreboard from the first file and add each climber to the list using the insert_sorted 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 1 or 3 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 lead(the 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 read/write functions in climber.cpp. The Climber struct is defined as follows:
struct Climber { char name[64]; char country[4]; 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, e.g.:
Climber c; while (read(in, c)){...
Tests for the read and write functions are provided in tests/test_a3.cpp.
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:
insert_sorted: 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 3 characters long.
The files will always have the word bouldering or lead in them (such as mens_bouldering.csv or womens_lead.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 (e.g. 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:
main.cpp The main program logic should do the

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 Programming Questions!