Dynamic List Class
Short Description:
Create a dynamic list class.
This assignment is worth 60 points.
Goals
When you finish this homework, you should:
- Have developed your skills designing and implementing a class.
- Have demonstrate you skills documenting an interface.
- Have developed your skills building multiple file implementations.
- Have developed your skills using a class with dynamic memory.
Formal Description
You should implement a dynamic list class. Your list class should contain elements of type ItemT, where each item has a key field. In this case, key will be a string. Your class should contain an index, which allows the user to step through the list. This class should contain the following member functions:
- int Size(): Return the number of elements in the list.
- bool IsPresent(key): returns true if key is in the list.
- void Delete(key): deletes all occurrences of key in the list
- void Insert(ItemT item): inserts item into the list
- ItemT Get(key): returns the item matching key.
- void ResetIndex(): Set the internal index to the first item in the list
- void NextItem(): move the internal index to the next item in the list. This will not advance past the last item in the list.
- bool IsLast(): returns true if the internal index is pointing to the last item in the list.
- ItemT GetIndex(): returns the value pointed to by the internal index.
- bool ValidIndex(): returns true if the index is not pointing to NULL.
ItemT has a member function key() which returns the value of
key associated with the instance.
Your list should be dynamic, and be ordered from the lowest key value to the highest.
You should further implement any additional member functions required for dynamic memory.
The internal index is invalid, and should be set to the first item, whenever items are inserted or deleted from the list. You should be able to use the index to iterate through the list.
ListT l;
...
for(l.Reset();!l.IsLast();l.NextItem()) {
cout << l.GetItem();
}
if (l.ValidIndex()) {
cout << l.GetItem();
}
To demonstrate your list, you should write two programs.
The first should test all member functions.
The second program should maintain three lists of students. These students
are classified as "good" if their grade average is 3.0 or higher, "average", if their grade average is 2.0 to 2.99, and "poor" if their grade average is below 2.0. Your program should read from the input file grades.dat, processing the following commands:
- grade average student_name: Assign the average to student_name
- add value student_name: Add a value to student_name's average, the value may be negative.
- query student_name: Print information about student_name, include if they are good, average or poor. If the student is not present, print a message explaining this.
- print class: Class will be good, average or poor. Print all of the students in this class.
- printall: Print all students in the data base. Clearly label the classes.
An example data file:
grade 2.98 Merlin
grade 3.01 Sir Kay
grade 1.0 Sir Robin
grade 4.00 Arthur King of the Britons
add .03 Sir Kay
add -.99 Sir Robin
query Arthur King of the Britons
query Lancelot
print good
printall
Discussion
- Your code should be well written and well documented.
- Your ItemT class should be implemented as a stand alone class with header and implementation files.
- Your ListT class should be implemented as a stand alone class with header and implementation files.
Required Files
You should submit the following in a tar file:
- All source code required to build all programs.
- A makefile which will build all programs as well as clean the directory
- A README describing
- Author identification information
- The project
- Problems encountered
- Any portions of the code which are not working.
- Any unique features of the code.
- Any other information you wish to share.
You should not submit
- Object files or executable.
- Core files.
- Source code files which are not related to the project.
Submission
Please create a tar file containing the files described above. Email this file to danbennett360@gmail.com by class time of the due date.