#include #include "assign4.h" #include static char *statusStrings[5] = { "Underflow", "Empty", "Pending", "Full", "Overflow" }; int main () { int item; int choice; int nextNum; int looping = 1; int random = 0; int i = 0; status currentStatus; while (looping == 1) { cout << "What would you like to do?\n"; cout << "\t1) Check queue status.\n"; cout << "\t2) Enter a number in the queue\n"; cout << "\t3) Get a number from the queue\n"; cout << "\t4) Perform full tests.\n"; cout << "\t5) Quit\n"; cin >> choice; if (choice == 1) { currentStatus = getStatus (); cout << "The current queue status is " << statusStrings[currentStatus] << "\n"; } if (choice == 2) { cout << "\nPlease enter a number to be placed on the queue --> "; cin >> item; currentStatus = putQueue (item); cout << "\nThe current status is now " << statusStrings[currentStatus] << "\n"; } if (choice == 3) { nextNum = getQueue (); cout << "The number you get is " << nextNum << "\n"; } if (choice == 4) { currentStatus = getStatus (); cout << "******************************\n"; cout << "Checking to see if status variable is initialized properly.\n"; if (currentStatus == EMPTY) cout << "Passed...your status is --> " << statusStrings[currentStatus] << "\n"; else cout << "Failed...your status is --> " << statusStrings[currentStatus] << "\n"; nextNum = getQueue (); cout << "******************************\n"; cout << "\nTrying to remove an item from the empty queue and then checking status.\n"; if (nextNum == 0) { cout << "You correctly returned 0 because the queue was empty.\n"; currentStatus = getStatus (); if (currentStatus == UNDERFLOW) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } } else { cout << "You didn't return the correct item.\n"; if (currentStatus == UNDERFLOW) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } } cout << "******************************\n"; cout << "Placing " << (QSIZE - 1) << " items on the queue\n"; for (i = 0; i < (QSIZE - 1); i++) { random = rand (); currentStatus = putQueue (random); } if (currentStatus == PENDING) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } cout << "******************************\n"; cout << "Placing one more item on the queue\n"; random = rand (); currentStatus = putQueue (random); if (currentStatus == FULL) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } cout << "******************************\n"; cout << "Placing an extra item on the queue\n"; random = rand (); currentStatus = putQueue (random); if (currentStatus == OVERFLOW) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } cout << "******************************\n"; cout << "Removing one item and checking the status\n"; nextNum = getQueue (); currentStatus = getStatus (); if (currentStatus == PENDING) { cout << "Passed...You have returned the correct status --> " << statusStrings[currentStatus] << "\n"; } else { cout << "You have returned the incorrect status --> " << statusStrings[currentStatus] << "\n"; } cout << "******************************\n"; } if (choice == 5) { looping = 2; } } return 0; }