Question: Write a c++ program to implement a queue using an array. Queue is a FIFO data structure where the insertions are made front the back
Write a c++ program to implement a queue using an array.
Queue is a FIFO data structure where the insertions are made front the back and deletions are made from back of the list.
Create a header file called queue.h. Copy the prototypes below. Create a cpp called queue.cpp and implement the functions. The queue should use an array of size 10. Use data hiding so outside files do not have direct global access to the array. The queue keeps a list of unique numbers. That is, the queue cannot have duplicate numbers. Program should be robust and should not crash.
int Enqueue ( int num ) adds num to the queue. Return 0 if success. Return -58 if queue is full. Return -62 if the queue already has num.
int Dequeue ( int& num ) removes the front item in the queue and places it in num. Return 0 if success. Return -64 if queue is empty.
int IsEmpty ( ) returns 1 if empty, 0 if not empty.
int Exists ( int num ) return 1 if num exists in the queue. Returns 0 if it does not exist.
void Clear ( void ) removes all items in the queue.
void Print ( void ) prints all items in the queue on ONE LINE with a space between each item and a linebreak at the end. Note that the queue should be displayed horizontally on the page. The first item added should be the first item displayed.
int Mul(void) multiplies the first two items in the queue and inserts the product in the front tof the queue. Return 0 if success. Returns - 79 if there are not at least two items. Returns -81 operation would cause an overflow. Returns -82 if the result of multiplying would cause a duplicate.
int Reverse ( void ) reverses all items in the queue. The first item becomes the last item. The second item becomes the second to last item, etc. Return 0 if success.
int Peek ( int& num ) gets the first item and places it in num, without removing it from the queue. Return 0 if success. Return -88 if fail.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
