/* Filename: quetest.cpp Programmer: Br. David Carlson Date: April 13, 1998. Last Revised: December 4, 2001 This is a menu-driven program that allows the user to insert items (floating-point numbers) into a queue, to remove them, and to check if the queue is empty. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include // for the tolower function #include "lstqueue.h" /* Given: Nothing. Task: To present a menu of available options on screen. Return: Nothing. */ void Menu(void) { cout << endl << "Menu of available Queue options:" << endl; cout << " I Insert an item" << endl; cout << " R Remove an item" << endl; cout << " E Check if queue is empty" << endl; cout << " Q Quit" << endl << endl; } /* Given: Nothing. Task: To read a letter from the keyboard indicating the user's choice. Return: This letter (in upper case) in the function name. */ char GetChoice(void) { char Temp; cin >> Temp; Temp = toupper(Temp); return Temp; } int main(void) { LstQueClass Queue; float Num; char Choice; Menu(); cout << "Enter the letter for your choice: "; Choice = GetChoice(); while (Choice != 'Q') { if (Choice == 'I') { cout << "Enter the float to insert into the queue: "; cin >> Num; Queue.Insert(Num); } else if (Choice == 'R') { Queue.Remove(Num); cout << "The number removed was: " << Num << endl; } else if (Choice == 'E') { if (Queue.Empty()) cout << "The queue is empty" << endl; else cout << "The queue is not empty" << endl; } else if (Choice != 'Q') cout << "Invalid Choice. You must use I, R, E, or Q." << endl; Menu(); cout << "Enter the letter for your choice: "; Choice = GetChoice(); } return 0; }