Question: In this project you will implement the array representation of the Unsorted List as a Generic ADT. Objectives: - Practice the array-based implementation of the





In this project you will implement the array representation of the Unsorted List as a Generic ADT. Objectives: - Practice the array-based implementation of the List ADT. - Practice implementing generic data types as template. - Practice implementing and using dynamically allocated arrays. - Practice using generic data types at the application level, with both primitive data types and user defined data types. Project Requirements: Use C++ template mechanism and define a generic Unsorted List ADT. Implement the Unsorted List ADT using a dynamically allocated array. I am attaching the UnsortedList.h file, the driver program, and the test files to this assignment. You need to implement the Unsorted list functions (Unsorted List.cpp) and complete the code of the driver program. ADT Unsorted List Specification: Private data members: 1. info: A dynamically allocated array Array elements are of type ItemType (The generic data type). 2. length: integer; stores the actual number of items in the list. Last occupied array index is length-1; 3. Max_Items: integer. The size of the list. Default value = 50 The Unsorted List ADT should implement the following public functions (defined in the attached file UnsortedList.h). Create and save the implementation in a file called UnsortedList.cpp. 1. Constructors Function: Initializes the list. Precondition: None. Postcondition: List is initialized. Implement the following constructors: 1.1 A no argument constructor to initialize Max_Items to 50. 1.2 A one argument constructor with a formal parameter size, that initializes Max_Items to size. Both constructors dynamically allocate the array info of size Max_Items. 2. bool isEmpty() const; Function: Determines if the list is empty. Precondition: List is initialized. Postcondition: The function returns true if the list is empty and false otherwise. 3. bool is Full() const; Function: Determines if the list is full. Precondition: List is initialized. Postcondition: The function returns true if the list is full and false otherwise. 4. int getLength() const; Function: Returns number of elements in the list. Precondition: List is initialized. Postcondition: Function value equals number of list elements. This function should run in constant time: 0(1) 5. void putItem (Item Type newItem); Function: Adds a new element to list. This function should not allow duplicate keys, and must check that there is space for the new item. Precondition: List is initialized. Postconditions: 1) new Item is in the list, if list is not full and newItem's key was not in the list. 2) The FullList exception is thrown if the list is full. 3) The DuplicateItem exception is thrown if newItem's keys was found in the list. This function should call the function findIndex (see function number 10 below) 6. void deleteltem (Item Type item); Function: Removes an element from the list. Precondition: List is initialized. Postconditions: item is not in the list. The Item NotFound exception is thrown if item was not found in the list. This function should call the function findIndex (see function number 10 below) This function should have a linear time T(n)=N+1 =0(N) i.e. O(N) to search +O(1) to delete the item logically. 7. Item Type getAt(int index) const; 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 the OutOfBound exception if the index not valid. (index = length of the list). 8. void makeEmpty(); Function: Reinitializes the list to empty state. Precondition: None. Postcondition: List is empty. 9. Unsorted List(); // class destructor Function: Deallocates all dynamically allocated data members. Precondition: None. Postcondition: List has been deallocated. 10. int findIndex (Item Type item); // helper function (private function) Function: Searches the list for item and returns item's index if the item was found. The function should return -1 if item was not in the list. This function should be used by your putItem and deleteItem functions. 1) Implement a simple Student class Implement a simple Student class with two data members: studentID (int) and studentName (String). Implement a constructor, setter, and getter functions for class Student. You may need to overload operators. For example, you may need to overload the operator == if your findIndex function compares two Student objects in the form: if (item=-info(i)), where info is an array of student objects. The operator ==should return true if the compared student objects have the same studentID and false otherwise. 2) The Unsorted List driver program: I am attaching the file UnsortedListDriver.cpp. This program will test your generic Unsorted List ADT. The attached file is ready to test the a list of integers, you need to complete the other test function, testSudentList(). To test the generic data type, we will define two lists of different datatypes; each is defined in the corresponding test function. UnsortedList-int>integerList(5); // list of integers of size 5 defined in testIntegerList() UnsortedList studentList(10); // Students list of size 10. Defined in testSudentList(). The attached driver UnsortedListDriver.cpp will start by reading an integer that represents the user choice of the type of list elements from the user. This input is from standard input (cin>>), not from the input file. Enter Elements Type 1 for integer 2 for student The test driver calls one of the test functions based on the elements type. The program will continue reading commands and data from the input file inFile until the command "Quit" is read. Commands are: (IsEmpty, IsFull, MakeEmpty, GetLength, GetAt, PutItem, Deleteltem, PrintList and Quit). Based on the command, the program will call the corresponding Unsorted List function and writes output to an output file outFile.txt. We will test your program with our command files (text files, see next section). So, make sure you are using the same commands and be aware of case sensitivity of the commands. (e.g. IsEmpty not isEmpty). 3) Text files: We will test your program with 2 text files, each contains testing commands for a specific data type. Your test driver should carefully associate the inFile with the corresponding commands file. Our command file for integer lists is called intcommands.txt. Our commands file to test a list of student objects is called studcommands.txt. I am attaching two sample test files to this project A sample execution is at the end of this project description, see Sample test execution (1) and (2) Make sure that the program will give the correct results and will not stop due to any run-time error. Sample test execution (1) 2 The left column is the command read from the command file, the right column is the expected output of the command written to outFile.txt; a blank line indicates that nothing will be written on the output file (so your output file should not contain blank lines and would look more compact than the example shown below). Command file(intcommands.txt) Expected output: outFile.txt Screen IsEmpty list is empty Is Full list is not full Enter Elements Type PutItem 10 PrintList 10 1 for int PutItem 2 2 for Student PrintList 10 2 1 DeleteItem 7 item is not in the list DeleteItem 10 PrintList DeleteItem 2 PrintList IsEmpty list is empty PutItem 7 PutItem 90 PutItem 5 PutItem 100 PutItem 3 PrintList 7 90 5 100 3 DeleteItem 90 PrintList 7 3 5 100 GetAt 0 Item at index 0 is: 7 GetAt 3 Item at index 3 is: 100 GetAt 5 index is out of range PutItem 6 PutItem 20 List is full, insertion failed ISFull List is full MakeEmpty PrintList Quit In this project you will implement the array representation of the Unsorted List as a Generic ADT. Objectives: - Practice the array-based implementation of the List ADT. - Practice implementing generic data types as template. - Practice implementing and using dynamically allocated arrays. - Practice using generic data types at the application level, with both primitive data types and user defined data types. Project Requirements: Use C++ template mechanism and define a generic Unsorted List ADT. Implement the Unsorted List ADT using a dynamically allocated array. I am attaching the UnsortedList.h file, the driver program, and the test files to this assignment. You need to implement the Unsorted list functions (Unsorted List.cpp) and complete the code of the driver program. ADT Unsorted List Specification: Private data members: 1. info: A dynamically allocated array Array elements are of type ItemType (The generic data type). 2. length: integer; stores the actual number of items in the list. Last occupied array index is length-1; 3. Max_Items: integer. The size of the list. Default value = 50 The Unsorted List ADT should implement the following public functions (defined in the attached file UnsortedList.h). Create and save the implementation in a file called UnsortedList.cpp. 1. Constructors Function: Initializes the list. Precondition: None. Postcondition: List is initialized. Implement the following constructors: 1.1 A no argument constructor to initialize Max_Items to 50. 1.2 A one argument constructor with a formal parameter size, that initializes Max_Items to size. Both constructors dynamically allocate the array info of size Max_Items. 2. bool isEmpty() const; Function: Determines if the list is empty. Precondition: List is initialized. Postcondition: The function returns true if the list is empty and false otherwise. 3. bool is Full() const; Function: Determines if the list is full. Precondition: List is initialized. Postcondition: The function returns true if the list is full and false otherwise. 4. int getLength() const; Function: Returns number of elements in the list. Precondition: List is initialized. Postcondition: Function value equals number of list elements. This function should run in constant time: 0(1) 5. void putItem (Item Type newItem); Function: Adds a new element to list. This function should not allow duplicate keys, and must check that there is space for the new item. Precondition: List is initialized. Postconditions: 1) new Item is in the list, if list is not full and newItem's key was not in the list. 2) The FullList exception is thrown if the list is full. 3) The DuplicateItem exception is thrown if newItem's keys was found in the list. This function should call the function findIndex (see function number 10 below) 6. void deleteltem (Item Type item); Function: Removes an element from the list. Precondition: List is initialized. Postconditions: item is not in the list. The Item NotFound exception is thrown if item was not found in the list. This function should call the function findIndex (see function number 10 below) This function should have a linear time T(n)=N+1 =0(N) i.e. O(N) to search +O(1) to delete the item logically. 7. Item Type getAt(int index) const; 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 the OutOfBound exception if the index not valid. (index = length of the list). 8. void makeEmpty(); Function: Reinitializes the list to empty state. Precondition: None. Postcondition: List is empty. 9. Unsorted List(); // class destructor Function: Deallocates all dynamically allocated data members. Precondition: None. Postcondition: List has been deallocated. 10. int findIndex (Item Type item); // helper function (private function) Function: Searches the list for item and returns item's index if the item was found. The function should return -1 if item was not in the list. This function should be used by your putItem and deleteItem functions. 1) Implement a simple Student class Implement a simple Student class with two data members: studentID (int) and studentName (String). Implement a constructor, setter, and getter functions for class Student. You may need to overload operators. For example, you may need to overload the operator == if your findIndex function compares two Student objects in the form: if (item=-info(i)), where info is an array of student objects. The operator ==should return true if the compared student objects have the same studentID and false otherwise. 2) The Unsorted List driver program: I am attaching the file UnsortedListDriver.cpp. This program will test your generic Unsorted List ADT. The attached file is ready to test the a list of integers, you need to complete the other test function, testSudentList(). To test the generic data type, we will define two lists of different datatypes; each is defined in the corresponding test function. UnsortedList-int>integerList(5); // list of integers of size 5 defined in testIntegerList() UnsortedList studentList(10); // Students list of size 10. Defined in testSudentList(). The attached driver UnsortedListDriver.cpp will start by reading an integer that represents the user choice of the type of list elements from the user. This input is from standard input (cin>>), not from the input file. Enter Elements Type 1 for integer 2 for student The test driver calls one of the test functions based on the elements type. The program will continue reading commands and data from the input file inFile until the command "Quit" is read. Commands are: (IsEmpty, IsFull, MakeEmpty, GetLength, GetAt, PutItem, Deleteltem, PrintList and Quit). Based on the command, the program will call the corresponding Unsorted List function and writes output to an output file outFile.txt. We will test your program with our command files (text files, see next section). So, make sure you are using the same commands and be aware of case sensitivity of the commands. (e.g. IsEmpty not isEmpty). 3) Text files: We will test your program with 2 text files, each contains testing commands for a specific data type. Your test driver should carefully associate the inFile with the corresponding commands file. Our command file for integer lists is called intcommands.txt. Our commands file to test a list of student objects is called studcommands.txt. I am attaching two sample test files to this project A sample execution is at the end of this project description, see Sample test execution (1) and (2) Make sure that the program will give the correct results and will not stop due to any run-time error. Sample test execution (1) 2 The left column is the command read from the command file, the right column is the expected output of the command written to outFile.txt; a blank line indicates that nothing will be written on the output file (so your output file should not contain blank lines and would look more compact than the example shown below). Command file(intcommands.txt) Expected output: outFile.txt Screen IsEmpty list is empty Is Full list is not full Enter Elements Type PutItem 10 PrintList 10 1 for int PutItem 2 2 for Student PrintList 10 2 1 DeleteItem 7 item is not in the list DeleteItem 10 PrintList DeleteItem 2 PrintList IsEmpty list is empty PutItem 7 PutItem 90 PutItem 5 PutItem 100 PutItem 3 PrintList 7 90 5 100 3 DeleteItem 90 PrintList 7 3 5 100 GetAt 0 Item at index 0 is: 7 GetAt 3 Item at index 3 is: 100 GetAt 5 index is out of range PutItem 6 PutItem 20 List is full, insertion failed ISFull List is full MakeEmpty PrintList Quit