Corrections, clarifications, and other announcements regarding this programming assignment will be found below.
In programming assignment 2 the issues of proper memory management for the Student and SortedList classes were ignored. The compiler defaults for the destructors, copy constructors, and copy assignment operators were assumed to be good enough. For this assignment you'll write your own to ensure that memory dynamically allocated in the classes is correctly managed. You'll also write a main function that demonstrates the usefulness of the added functions.
The goals of this assignment are to gain experience:
Add the following to the Student class you wrote for Programming Assignment 2:
Make sure to modify both Student.h and Student.cpp.
Add the following to the SortedList class you wrote for Programming Assignment 2:
Make sure to modify both SortedList.h and SortedList.cpp.
Both the destructor and copy assignment operator of the SortedList class must deallocate the nodes of a linked list returning them to the free storage (i.e., the heap). Both the copy constructor and copy assignment operator make a deep copy of an existing linked list. Therefore, it is a good idea to write two auxiliary functions to handle these two tasks.
private: static void freeList (ListNode *L); static ListNode *copyList (ListNode *L);
Implement an auxilliary function, named freeList, having one parameter, a pointer to a ListNode. This function traverses the linked list, returning each node to free storage. It is used by both the destructor and copy assignment operator.
Also implement an auxilliary function, named copyList, having one parameter, a pointer to a ListNode. This function returns a pointer to the first node of a copy of original linked list. It is used by both the copy constructor and the copy assignment operator.
Note both auxilliary functions are implemented as static functions of the SortedList class and should be used as such. They are also private intended to only be used within the class. Also note in SortedList.cpp the the modifier "static" is not included.
Write a main function, in the file main.cpp that tests your new version of the Student and SortedList classes. This function should fully exercise the destructors, copy constructors, and copy assignment operators of each class.
Next, use valgrind to make two instrumented executables one version using the class implementations from programming assignment 2 and another using your updated classes. When the first version is run, valgrind should report storage leaks, but there should be none for your second version.
Finally, compare the differences between the Student class and the SortedList class. Determine for which class(es) the updates mattered. Include your conclusions in the header comments of the main.cpp file.
Make sure your code follows the style and commenting standards used in CS 302 and CS 367. Note: the commenting standards use javadoc comments for class, method, and constructor headers. You do not need to use javadoc comments in your c++ programs for CS 368; however, your comments should include the same information as the javadoc comments. For example, your function header comments should include a description of what the function does, the name and a short description of each parameter, and a description of the return value.
Electronically submit the following file to your in "handin" directory by the due date and time (or refer to the late policy):
Please turn in only the files named above. Extra files clutter up the "handin" directories.
Last Updated: 10/23/2013 © 2012-2013 CS368 Instructors