Question: Objectives To learn about abstract data types. To learn about classes and objects. To gain experience writing client code which instantiates objects and invokes their

Objectives
To learn about abstract data types.
To learn about classes and objects.
To gain experience writing client code which instantiates objects and invokes their methods.
To gain experience designing and implementing a class.
As usual, this assignment is to be completed without the use of containers like std::string, std::vector, smart pointers, or other convenience features.
The starter code contains the following files:
climber.h: As before, this contains the Climber structure and associated I/O function declarations, but this time, theyre operators.
scoreboard.h: This is a scarily blank looking file, with just the include guards and barebones class declaration. You will need to decide what functionality to provide and how to implement it.
main.cpp
Your main function should be very simple. It should perform the functionality described in assignment 3, but it should not contain any linked list code. Instead, it should create Scoreboard objects as needed, then call the appropriate methods on those objects. For reference, my mainfunction is only about 20 lines of code.
Key features of your new main function:
You should not need to use any pointers in main.cpp - this means no new or delete operators.
Similarly, you should not create any Node pointers or objects. If you have implemented your class correctly, a Node declaration in main.cpp should fail to compile.
Depending on your class design decisions, sample usage might look like:
// Create a scoreboard directly from a filename Scoreboard sb1(argv[1]); // do some error checking // and figure out whether the first file is boulder or lead sb1.display(std::cout, category_name_1); if (argc >2){ Scoreboard sb2(argv[2]); // more error checking // Create the combined scoreboard Scoreboard sb3= sb1+ sb2; // Print them out sb2.display(std::cout, category_name_2); sb3.display(std::cout, "Combined"); // no need to delete anything, the destructor is called automagically! }
This example assumes that youve defined a constructor that takes a filename as an argument, an overloaded + operator, and a displayfunction that takes both an output stream and the title of the scoreboard.
If youre running in to issues with the + operator, you could do something else like:
Scoreboard sb3; sb3.merge(sb1); sb3.merge(sb2);
which avoids returning a Scoreboard object by value.
climber.cpp
All that really needs to be done is changing the read and write functions to behave as operator >> and operator , respectively.
The extraction (>>) operator should be nearly identical to the read function. For the write function (now the operator), the order of parameters and the return value have changed (basically it should just return the stream reference at the end of the function).
scoreboard.cpp
I recommend at the very least moving your assignment 3 functions into this class - just remember to remove the Node *head parameter from the argument list.Use const wherever possible.
private implementation details
Your Node struct should be declared as a private member of the Scoreboard class.You can also define any private helper functions or additional member variables here (I recommend a Node *head variable!).
Tips:
The Scoreboard class is responsible for managing the memory of the Climber objects. You will need to implement a destructor to free the memory when the Scoreboard object goes out of scope. A simple way to do this is to just call your own clear function.
Some of the functionality from assignment 3s main can be moved into the Scoreboard class. For example, you could define a mergemember function that takes another Scoreboard instance, (or overload the + operator if you want to get fancy).
NEEDS TO PASS TEST:
#include using namespace std; #include #include #include #include #include #include "../climber.h" #include "../scoreboard.h" bool operator==(const Climber &lhs, const Climber &rhs){ return strcmp(lhs.name, rhs.name)==0 && strcmp(lhs.country, rhs.country)==0 && abs(lhs.score - rhs.score)1e-6; } class ClimberTest : public ::testing::Test { protected: stringstream toby_ss = stringstream("GBR,Toby Roberts,63.1"); stringstream climbers_ss = stringstream("GBR,Toby Roberts,63.1
""JPN,Soratu Anraku,69.3
" "AUT,Jakob Schubert,43.6
"); Climber toby ={"Toby Roberts", "GBR",63.1}; Climber climbers[3]={toby,{"Soratu Anraku", "JPN",69.3},{"Jakob Schubert", "AUT", 43.6}}; }; // Climber tests TEST_F(ClimberTest, ReadSingle){ Climber c; toby_ss >> c; EXPECT_EQ(c, toby); } TEST_F(ClimberTest, ReadMultiple){ Climber c; for (int i =0; i 3; ++i){ climbers_ss >> c; EXPECT_EQ(c, climbers[i]); }} TEST_F(ClimberTest, WriteSingle){ stringstream out; out toby; EXPECT_EQ(out.str(),"GBR Toby Roberts 63.1"); } TEST_F(ClimberTest, WriteMultiple){ stringstream out; for (int i =0; i 3; ++i){ out climbers[i]'
'; } EXPECT_EQ(out.str(),"GBR Toby Roberts 63.1
""JPN Soratu Anraku 69.3
" "AUT Jakob Schubert 43.6
"); }
Objectives To learn about abstract data types. To

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!