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 #include #include

template class SortedList { public: SortedList(); bool isEmpty() const; bool isFull() const; int getLength() const; void insertItem(ItemType newItem); void deleteItem(ItemType item); ItemType get(int index); void makeEmpty(); void prtinList(); ~SortedList();

private: int length; int MAX_ITEMS; ItemType *info; int findIndex(ItemType item); };

SortedList.cpp

#include "SortedList.h" #include #include

template SortedList::SortedList() { MAX_ITEMS = 50; info = new ItemType[MAX_ITEMS]; length = 0; }

template bool SortedList::isEmpty() const { return (length == 0); }

template bool SortedList::isFull() const { return (length == MAX_ITEMS); }

template int SortedList::getLength() const { return length; }

template void SortedList::insertItem (ItemType newItem) { int location = 0;

while(location < length) { if(newItem location; index --) info[index] = info [index - 1];

info[location] = newItem; length++; }

template void SortedList::deleteItem (ItemType item) { int location = 0; while (item != info[location]) location++; for (int index = location + 1; index

length--; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!