Question: Use C++ template mechanism and define a generic SortedList ADT. Implement the SortedList ADT using a dynamically allocated array Add the following methods to SortedList.cpp
Use C++ template mechanism and define a generic SortedList ADT. Implement the SortedList ADT using a dynamically allocated array
Add the following methods to SortedList.cpp and Implement a simple Student class
Implement a simple Student class with two data members: StudentID (int) and Student name (String). Implement a constructor and setter functions for class Student. You must also overload operators ==, < and > for class Student in order to be able to compare objects. For example, the operator == should return true if compared student objects have the same StudentID and false otherwise.
Methods to be added to SortedList.cpp
ItemType get(int index);
Function: Returns the element at the specified position (index) in this list. Precondition: List is initialized. Postcondition: The function returns the element at the specified position in this list.
or throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= length of the list).
void makeEmpty();
Function: Reinitializes the list to empty state. Deallocates all dynamically allocated data members. Precondition: None. Postcondition: List is empty.
void printList();
Function: Prints list elements. Precondition: list is initialized. Postcondition: List elements are displayed on the screen.
~SortedList(); // class destructor Function: Reinitializes the list to empty state. Deallocates all dynamically allocated data members. Precondition: None. Postcondition: List is empty.
----------------------------------------
SortedList.h
#include
template
private: int length; int MAX_ITEMS; ItemType *info; int findIndex(ItemType item); };
SortedList.cpp
#include "SortedList.h" #include
template
template
template
template
template
while(location < length) { if(newItem
info[location] = newItem; length++; }
template length--; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
