Question: please comment out the calls to various tests from main() #include #include #include SortedListHasA.h // ADT sorted list operations using namespace std; void displayList(SortedListInterface *

please comment out the calls to various tests from main()

#include #include #include "SortedListHasA.h" // ADT sorted list operations

using namespace std;

void displayList(SortedListInterface* listPtr) { cout << "The sorted list contains " << endl; for (int pos = 1; pos <= listPtr->getLength(); pos++) { cout << listPtr->getEntry(pos) << " "; } // end for cout << endl << endl; } // end displayList

void copyConstructorTester() { SortedListHasA list; string items[] = {"zero", "one", "two", "three", "four", "five"}; for (int i = 0; i < 6; i++) { cout << "Adding " << items[i] << endl; list.insertSorted(items[i]); } displayList(&list); SortedListHasA copyOfList(list); cout << "Copy of list: "; displayList(©OfList); cout << "The copied list: "; displayList(&list); } // end copyConstructorTester

void sortedListTester(SortedListInterface* listPtr) { string luke = "Luke"; string brent = "Brent"; string donna = "Donna"; string tom = "Tom"; string sue = "Sue"; string jerry = "Jerry"; cout << " Test isEmpty with an empty list:" << endl; if (listPtr->isEmpty()) cout << "OK" << endl; else cout << "isEmpty() error" << endl; listPtr->insertSorted(luke); listPtr->insertSorted(brent); listPtr->insertSorted(donna); listPtr->insertSorted(tom); listPtr->insertSorted(sue); listPtr->insertSorted(jerry); // display the list cout << "List should contain Brent, Donna, " << "Jerry, Luke, Sue, Tom" << endl; cout << " List actually contains:" << endl; displayList(listPtr); cout << endl; // test getPosition cout << " Test getPosition: " << endl; // These names are in the list cout << "Brent is at position " << listPtr->getPosition(brent) << endl; cout << "Donna is at position " << listPtr->getPosition(donna) << endl; cout << "Jerry is at position " << listPtr->getPosition(jerry) << endl; cout << "Luke is at position " << listPtr->getPosition(luke) << endl; cout << "Sue is at position " << listPtr->getPosition(sue) << endl; cout << "Tom is at position " << listPtr->getPosition(tom) << endl; // These names are not in the list string missy = "Missy"; cout << "Missy belongs at position " << listPtr->getPosition(missy) << endl; string zeke = "Zeke"; cout << "Zeke belongs at position " << listPtr->getPosition(zeke) << endl; string aaron = "Aaron"; cout << "Aaron belongs at position " << listPtr->getPosition(aaron) << endl; // test getLength and getEntry cout << " Test getLength and getEntry: " << endl; cout << " List has " << listPtr->getLength() << " entries, as follows: " << endl; for (int i = 1; i <= listPtr->getLength(); i++) cout << i << ": " << listPtr->getEntry(i) << endl; // test remove cout << " Test remove: " << endl; // remove first entry cout << " Removing first item (Brent): " << listPtr->removeSorted(brent) << "; should be 1 (true)" << endl; cout << " After removing Brent, list contains " << listPtr->getLength() << " items, as follows:" << endl; displayList(listPtr); // remove interior cout << " Removing interior item (Luke): " << listPtr->removeSorted(luke) << "; should be 1 (true)" << endl; cout << " After removing Luke, list contains " << listPtr->getLength() << " items, as follows:" << endl; displayList(listPtr); // remove last cout << " Removing last item (Tom): " << listPtr->removeSorted(tom) << "; should be 1 (true)" << endl; cout << " After removing last item, list contains " << listPtr->getLength() << " items, as follows:" << endl; displayList(listPtr); cout << " Removing a missing item (Brent): " << listPtr->removeSorted(brent) << "; should be 0 (false)" << endl; cout << " Removing a missing item (Luke): " << listPtr->removeSorted(luke) << "; should be 0 (false)" << endl; cout << " Removing a missing item (Tom): " << listPtr->removeSorted(tom) << "; should be 0 (false)" << endl; cout << " The list contains " << listPtr->getLength() << " items, as follows:" << endl; displayList(listPtr); // test clear() cout << " Test clear(): " << endl; listPtr->clear(); if (listPtr->isEmpty()) cout << " The list is empty after invoking clear()." << endl; else cout << " clear() error" << endl; } // end sortedListTester

void listOpsTester(SortedListInterface* listPtr) { string luke = "Luke"; string brent = "Brent"; string donna = "Donna"; string tom = "Tom"; string sue = "Sue"; string jerry = "Jerry"; listPtr->insertSorted(luke); listPtr->insertSorted(brent); listPtr->insertSorted(donna); listPtr->insertSorted(tom); listPtr->insertSorted(sue); listPtr->insertSorted(jerry); displayList(listPtr); cout << "isEmpty: returns " << listPtr->isEmpty() << "; should be 0 (false)" << endl; cout << "getLength returns : " << listPtr->getLength() << "; should be 6" << endl; cout << "remove(2): returns " << listPtr->remove(2) << "; should be 1 (true)" << endl; cout << "remove(1): returns " << listPtr->remove(1) << "; should be 1 (true)" << endl; cout << "remove(6): returns " << listPtr->remove(6) << "; should be 0 (false)" << endl; displayList(listPtr); cout << "getLength returns : " << listPtr->getLength() << "; should be 4" << endl; cout << "clear: " << endl; listPtr->clear(); cout << "isEmpty: returns " << listPtr->isEmpty() << "; should be 1 (true)" << endl; try { cout << "Attempt an illegal retrieval from position 6: " << endl; listPtr->getEntry(6); } catch(PrecondViolatedExcep e) { cout << e.what() << endl; } // end try/catch } // end listOpsTester

int main() { copyConstructorTester();

SortedListInterface* intList = new SortedListHasA();

SortedListInterface* listPtr = new SortedListHasA(); cout << "Testing the Link-Based Sorted List:" << endl; sortedListTester(listPtr); cout << "======================================" << endl; cout << " Testing the List Operations:" << endl; listOpsTester(listPtr);

return 0; } // end main

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!