#include const int MAXQUEUE = 100; const int TRUE = 1; const int FALSE = 0; // class declaration // preconditions: requires that MAXQUEUE, the maximum size of the // : queue, be defined // : requires that TRUE be defined as a nonzero integer // : requires that FALSE be defined as 0 class Queue { private: int queueIn; // top-of-queue position int num[MAXQUEUE]; public: Queue(); // constructor void enqueue(int); int serve(); int isempty(); int isfull(); }; // implementation section Queue::Queue() // constructor { queueIn = -1; // initialize the top-of-queue position } void Queue::enqueue(int value) { queueIn++; // increment the index stored in queueIn num[queueIn] = value; // store the value return; } int Queue::serve() { int i, botval; botval = num[0]; // retrieve the first array element for(i = 0; i < queueIn; i++) // shift all elements down num[i] = num[i+1]; queueIn--; return(botval); } int Queue::isempty() { if (queueIn == -1) return TRUE; else return FALSE; } int Queue::isfull() { if (queueIn == MAXQUEUE - 1) return TRUE; else return FALSE; } int main() { Queue digits; // define a Queue named digits int newnum; cout << "Enter as many digits as you wish, one per line" << "\nTo stop entering digits, enter a number greater than 9\n"; while (1) { cout << "Enter a digit: "; cin >> newnum; if (newnum > 9) break; if (digits.isfull()) // check for overflow { cout <<"\nNo more storage allocation space" << "\nThe last digit has not been entered on the queue" << endl; break; } else digits.enqueue(newnum); // enqueue value onto the queue } // serve and display digits from the queue cout << "\nThe values served from the queue are:\n"; while(!digits.isempty()) // check for underflow { cout << digits.serve() << endl; } return 0; }