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 IO 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 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 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 sbargv; do some error checking and figure out whether the first file is boulder or lead sbdisplaystd::cout, categoryname; if argc Scoreboard sbargv; more error checking Create the combined scoreboard Scoreboard sb sb sb; Print them out sbdisplaystd::cout, categoryname; sbdisplaystd::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 sb; sbmergesb; sbmergesb;
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 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 s 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 climberh #include scoreboardh bool operatorconst Climber &lhs const Climber &rhs return strcmplhsname, rhsname && strcmplhscountry, rhscountry && abslhsscore rhsscoree; class ClimberTest : public ::testing::Test protected: stringstream tobyss stringstreamGBRToby Roberts,; stringstream climbersss stringstreamGBRToby Roberts,
JPNSoratu Anraku,
"AUT,Jakob Schubert,
; Climber toby Toby Roberts", GBR; Climber climberstobySoratu Anraku", JPNJakob Schubert", "AUT", ; ; Climber tests TESTFClimberTest ReadSingle Climber c; tobyss c; EXPECTEQc toby; TESTFClimberTest ReadMultiple Climber c; for int i ; i ; i climbersss c; EXPECTEQc climbersi; TESTFClimberTest WriteSingle stringstream out; out toby; EXPECTEQoutstrGBR Toby Roberts ; TESTFClimberTest WriteMultiple stringstream out; for int i ; i ; i out climbersi
; EXPECTEQoutstrGBR Toby Roberts
JPN Soratu Anraku
"AUT Jakob Schubert
;
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
