/* ---------------------------------------------------------------------- MEMORIAL UNIVERSITY OF NEWFOUNDLAND Faculty of Engineering and Applied Science Engineering 3891(Advanced Programming) Assignment #4 Instructor: Michael Bruce-Lockhart Date: 00.10.06 Due: 00.10.13 ---------------------------------------------------------------------- Interface for a circular queue manager */ const int QSIZE = 2000; // size of queue in bytes /*NOTE: you may want to change this to something like 4 or 5 when debugging. However, it will be set to 2000 when the autograder runs its tests. */ enum status{UNDERFLOW,EMPTY,PENDING,FULL,OVERFLOW}; /* Queue status: empty: nothing in the queue pending: more than 0 and less than QSIZE items in the queue full - queue has exactly QSIZE items in it overflow -queue is full AND at least one attempt has been made to add more items so that an error has occurred. Number of such items (the data lost) is undefined. underflow - queue is empty AND at least one attempt has been made to remove non-existent data from it. Note that overflow and full are both set to pending if a single item is removed from the queue while underflow and empty both set to pending if a single item is added to the queue. */ status getStatus(void); /* returns current status of the queue */ status putQueue(int item); /* Puts item on the queue, updates and returns new status. If the queue is already full or in overflow, current item is lost but all items put on the queue previously are unaffected. */ int getQueue(void); /* Returns integer item from the queue. Status is updated but not returned. Returns 0 if no items available */ /* EXPLANATION A circular queue is a first-in, first-out data structure. New entries are always made at the tail and old entries are removed from the head. Unlike a bank queue, entries are not actually moved up in the queue as the head is serviced. Rather, they are like the service number systems used in many stores, whereby a new customer takes the next number from the machine (the tail pointer) and finds any open place at the counter. The clerk, meanwhile, serves customers according to the next service number appearing on an electronic counter (the head pointer). The numbers are changed, but the customers don't move. The queue is circular because the numbers rotate around in sequence. Generally, the dispensers only have nos. 0 through 99 available. After 99 is used they go back to 0. You are to create the three routines required for the implementation (one of which is trivial so you really only have to write two). The three functions are to be implemented in a single file which should incorporate the following, external database: (i.e outside all functions in the file, declared at the beginning of the file, and hence visible to all functions in the file). int queue[QSIZE]; int* head; // access pointers to the beginning int* tail; // and end of the queue status current; This code should appear after any #include statements you require but before your function implementations. Its effect is to make the queue, its current status and its two pointers visible to all three functions, so each can operate on the queue. Thus the application cannot directly manipulate the queue or its pointers but must work through the publicly available functions declared in the interface. This is a concept known as DATA HIDING. Any of these four variables can be initialised if you want. As they are external variables they exist for the life of the program and hence are only initialised once, when the program is loaded (just before main is called). This is in contrast to internal variables which are created anew each time their function is called and thus have to be initialised anew (if the ptogrammer has called for their initialisation). Note that none of the functions are very long. The trick is to be able to work out the status of the queue at all times. No other global variables should be used and local variables should be kept to a minimum. Note also that there is nothing to stop you creating your own service functions in your assign4.cpp file. Since they are not declared in the h file they will not be available/visible to the test routine but they WILL BE available to your functions. For example, since your pointers have to run around a circle, you might consider creating a pointer increment function to deal with that problem. PLEASE NOTE: YOU ARE EXPECTED TO USE POINTER, RATHER THAN ARRAY, NOTATION! */