Question: c++ How would I make this test driver? 2.6 (TestDriver) Implement the test program (TestDriver.cpp). This program must have SortedUserType useList : all users in

c++ How would I make this test driver?

2.6 (TestDriver) Implement the test program (TestDriver.cpp). This program must have

  • SortedUserType useList: all users in the input file will be inserted in this object
  • void PrintNextUser(ofstream& outFile, SortedUserType list): this function writes the current user, at the location of the item accessed by GetNextUser() function. This function must call ToString() function of the Use class.
  • void PrintList(ofstream& outFile, SortedUserType list): this function writes all items in the list to the output file. This function must use the GetNextItem() function of the SortedUserType class and it must call the ToString() function of the User class.
  • The TestDriver program must test all functions of the SortedUserType listed above.
  • Note: if you want, you can change the signatures of PrintNextUser and/or PrintList to pass in references to the output file and the considered list: ofstream& outFile, SortedUserType &list

This is the source code that has the functions:

//File SortedUserType.cpp contains the implementation of class SortedUserType #include "SortedUserType.h" #include #include using namespace std;

struct NodeUser { User userInfo; NodeUser* next; };

SortedUserType::SortedUserType()//class constuctor { maxList = 5; length = 0; listData = NULL; }

bool SortedUserType::IsFull() const //function: checks if list is full //pre: Initilizes list //post: functions value will be full { if (length == maxList) return true; else { NodeUser* location; try { location = new NodeUser; delete location; return false; } catch (bad_alloc exception) { return true; } } }

void SortedUserType::DeleteUser(User* user) //Fucntion: deletes the element whose output match user input /* Pre: list and key member of user has been inilitiazed list is sorted by key member using function compredTo

Post: rewrite */

{ NodeUser* location = listData; NodeUser* tempLocation; User* userInList = new User; *userInList = location->userInfo;

//find node to delete if (user->comparedTo(userInList) == EQUAL) { tempLocation = location; listData = listData->next; //deletes first node } else { *userInList = (location->next)->userInfo;

while (user->comparedTo(userInList) != EQUAL) { location=location->next; *userInList = (location->next)->userInfo; }

//delete the nodes location tempLocation = location->next; location->next = (location->next)->next; } delete tempLocation; length--; }

void SortedUserType::ResetList() { currentPos = NULL; }

void SortedUserType::MakeEmpty() { NodeUser* temp; while (listData != NULL) { temp = listData; listData = listData->next; delete temp; } length = 0; }

int SortedUserType::GetLength() const { return length; }

User* SortedUserType::GetUser(User* user, bool &found) const { bool search; NodeUser* location = listData; User* userInList = new User; *userInList = location->userInfo;

found = false; search = (location != NULL);

while (search && !found) { switch (user->comparedTo(userInList)) { case GREATER: location = location->next; search = (location != NULL); break; case EQUAL: found = true; user = userInList; break; case LESS: search = false; break; } } return user; }

void SortedUserType::PutUser(User* user) { NodeUser* location = user; User* userInList = new User; *userInList = location->userInfo;

NodeUser* newUser; NodeUser* prevLoc; NodeUser* location; bool search;

location = listData; prevLoc = NULL; search = (location != NULL); //find insertion point while (search) { switch (user->comparedTo(userInList)) { case GREATER: prevLoc = location; location = location->next; search = (location != NULL); break; case LESS: search = false; break; } } //prep nodes to insert newUser = new NodeUser; userInList = user;

//insert node into the list if (prevLoc == NULL) //insert at first { newUser->next = listData; listData = newUser; } else { newUser->next = location; prevLoc->next = newUser; } length++; }

User* SortedUserType::GetNextUser() { User* user; if (currentPos == NULL) currentPos = listData; user = &(currentPos->userInfo); currentPos = currentPos->next; return user; }

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!