Assignment 4: Refactoring the Leaderboard Program

Mar 25, 2024  β”‚  m. Apr 3, 2024 by Charlotte Curtis

Due Monday, April 8th at 11:59 PM

Overview

Customers (and bosses, and professors) are fickle. They change their minds and requirements just when you think you’ve got a problem solved. In this assignment, you’ll be refactoring your previous assignment to do the same thing, but using an object oriented paradigm.

In object oriented design, data structures and functionality are encapsulated in classes. The client code creates objects and communicates with them via their public interface, but the “how” is completely hidden 1.

For this assignment you will still be implementing a linked list, but your client code (main.cpp) should have no knowledge that you are using a linked list. Instead, you will create an abstract data type (ADT) called Leaderboard, and main will only interact with various Leaderboard objects and their public member functions (aka methods).

Objectives

Program functionality

Your program functionality should be exactly as described in assignment 3 , so that will not be repeated here.

Starter code

Grab the starter code using the following command:

$ git clone /library/students/comp1633/a4.git/

Then run git-asg-config and select a4 to configure your push repository.

The starter code contains the following files:

To provide some more guidance, I will be posting my (imperfect, and certainly not only) solution to assignment 3 after the last possible late day (Friday, March 29) for you to use as a starting point.

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 Leaderboard objects as needed (passing the appropriate input file stream to the Leaderboard constructor), and then call the appropriate methods on those objects.

Tips:

team.cpp

If you’re happy with your implementation from assignment 3, I would recommend copying this file over and making the necessary changes. 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.

leaderboard.cpp

Again, I recommend copying your assignment 3 implementation and starting from there. You will need to add:

In addition, you will need to modify the update, remove, and clear functions to be class member functions, which means you no longer pass the head pointer as a parameter. Instead, you will use a private member variable to keep track of the head of the list.

Tips:

Marking scheme

This assignment is worth 8% of your final grade and roughly divided as:

Refer to the style guide for a reference on style and documentation. If you use external resources such as Stack Overflow, ChatGPT, or a friend in the class, make sure to cite them in your comments. Failure to cite external resources will be considered plagiarism. An example of a citation is as follows:

// ChatGPT helped me with this function
void foo(int bar) {
    // ...
}

If your solution uses vectors or other data structures or techniques not covered in class, you will receive a reduced grade, possibly as low as 0. If you have previous experience, try to challenge yourself to solve this problem using only the basics.

In addition, there will be an automatic 20% deduction if your code fails to compile or run. If the problem is extreme and I cannot fix it with a small change, a grade of 0 may be assigned. Make sure your code compiles and runs on INS with the given makefile before submitting.

Finally, make sure to check your code periodically for memory leaks with valgrind. Memory leaks will incur a penalty of up to 10%, even if the code appears to function perfectly.


  1. Okay, not completely hidden - you can see the private declarations in the class header ↩︎



Previous: Assignment 3: Linked List Leaderboard