kse989 0 Newbie Poster

The assignment is to, using the given header file, write an implementation file, a menu-driven test file, and a car wash simulator... Please see attachment for complete instructions

This is what I have so far, I am having trouble with my print function... I am new to Queues and not really that sure of what I'm doing. If you see anything that I'm doing wrong, please let me know

queue.h

//Header file for Queue ADT - Linked
// Template class for dynamically allocated queue - rear pointer tracked only
// Nodes for queue are allocated and deallocated as needed
#ifndef QUEUE_TYPE
#define QUEUE_TYPE
#include <iostream>
using namespace std;

#include <new>
using std::bad_alloc;


class FullQueue                                 // FullQueue output of errors
{};

class EmptyQueue                                // EmptyQueue output of errors
{};


// DYNAMICALLY LINKED IMPLEMENTATION OF QUEUE

template <class ItemType>       // record type for nodes on queue
struct NodeType
{
    ItemType info;
    NodeType * next;
};

template <class ItemType>
class QueueType
{
    public:

        QueueType();
        QueueType(const QueueType &);  // Copy constructor
        ~QueueType();                // Class destructor.

        void MakeEmpty();              // Initializes the queue to an empty state
        bool IsEmpty() const;            // Determines whether the queue is empty.
        bool IsFull() const;               // Determines whether the queue is full.

        void Enqueue(ItemType newItem);    // Adds newItem to the rear of the queue.
        void Dequeue(ItemType & item);     // Removes front item from the queue and
        // returns it in the parameter.

        ostream & Print(ostream &);        // Prints contents of queue to screen
        QueueType& operator= (const QueueType &);     // Function: operator=

    private:
        NodeType<ItemType>* front;      // pointer to front node
        NodeType<ItemType>* rear;       // pointer to rear node
};




//-----------------------------------------------------------------
// Constuctor
// Pre: nothing has been initialized
// Post: both pointers will be initialized
template <class ItemType>
QueueType<ItemType>::QueueType()
{
        front = NULL;
        rear = NULL;
}


//-----------------------------------------------------------------
// Function: MakeEmpty()
// Pre: "right" queue has been initialized
// Post: Queue is empty
template <class ItemType>
void QueueType<ItemType>::MakeEmpty()
{
        NodeType<ItemType>* tempPtr;

        while (front != NULL)
        {
                tempPtr = front;
                front = front->next;
                delete tempPtr;
        }

        rear = NULL;
}


//-----------------------------------------------------------------
// Copy Constuctor
// Pre: "right" queue has been initialized
// Post: Queue contains all elements contained in "right" queue
template <class ItemType>
QueueType<ItemType>::QueueType(const QueueType<ItemType> & right)
{

        if (right.front != NULL)
        {
                NodeType<ItemType> * rightPtr = right.front;
                rear = front =  NULL;

                do
                {
                        Enqueue (rightPtr->info);
                        rightPtr = rightPtr->next;
                }
                while (rightPtr !=NULL);
        }
        else
                rear = front = NULL;
}


//-----------------------------------------------------------------
// Deconstuctor
// Pre: MakeEmpty function initialized
// Post: Deconstructor initialized
template <class ItemType>
QueueType<ItemType>::~QueueType()
{
        MakeEmpty();
}


//-----------------------------------------------------------------
// Function: IsFull - // Returns true if there is no room for another ItemType
//  on the free store; false otherwise.
// Pre: Queue has been initialized
// Post: Queue is not modified
template<class ItemType>
bool QueueType<ItemType>::IsFull() const
{
        NodeType<ItemType>* location;
        try
        {
                location = new NodeType<ItemType>;
                delete location;

                return false;
        }
        catch(bad_alloc &memoryAllocationException)
        {
                return true;
        }
}



//-----------------------------------------------------------------
// Function: IsEmpty - // Returns true if empty
// Pre: Queue has been initialized
// Post: Queue is not modified
template <class ItemType>
bool QueueType<ItemType>::IsEmpty() const
{
        return (front == NULL);
}


//-----------------------------------------------------------------
// Function: Enqueue - // Adds new item to rear of the queue
// Pre: Queue has been initialized
// Post: If (queue is not full).  newItem is at the rear of queue
//       If not, a FullQueue exception is thrown
template <class ItemType>
void QueueType<ItemType>::Enqueue(ItemType newItem)
{
        if (IsFull())
                throw FullQueue();
        else
        {
                NodeType<ItemType>* newNode;

                newNode = new NodeType<ItemType>;
                newNode->info = newItem;
                newNode->next = NULL;

                if (rear == NULL)
                        front = newNode;
                else
                        rear->next = newNode;
                rear = newNode;
        }
}


//-----------------------------------------------------------------
// Function: Dequeue - // Removes front item from the queue and returns it
// Pre: Queue has been initialized
// Post: If (queue is not empty) front of queue is removed and a copy returned
//       else EmptyQueue exception is thrown
template <class ItemType>
void QueueType<ItemType>::Dequeue(ItemType& item)
{
        if (IsEmpty())
                throw EmptyQueue();
        else
        {
                NodeType<ItemType>* tempPtr;

                tempPtr = front;
                item = front->info;
                front = front->next;

                if (front == NULL)
                        rear = NULL;

                delete tempPtr;
        }
}



//-----------------------------------------------------------------
// Function: Print - // Prints Results of queue
// Pre:
// Post: Cout << statetment of queue contants
template <class ItemType>
ostream & QueueType<ItemType>::Print(ostream & stream)
{
        int counter;
        counter = rear;

        stream << "The queue contains: " << endl;

        while (counter != 0)
        {
                stream << counter << " ";
                counter--;
        }
        return stream;
}

#endif

This is my test program so far
queueTest.cpp

#include <iostream>
#include "queue.h"
using namespace std;

int main()
{
        int num, item;
        QueueType<int> queue;
 while (num != 0)                        // an input of 0 will end program
        {
                cout << endl;
                cout << "Please select from the following options:" << endl;
                cout << '\t' << "1  - Add an item" << endl;
                cout << '\t' << "2  - Remove an item" << endl;
                cout << '\t' << "3  - Determine if stack is full" << endl;
                cout << '\t' << "4  - Determine if stack is empty" << endl;
                cout << '\t' << "5  - Clear all items from stack" << endl;
                cout << '\t' << "6  - Print" << endl;
                cout << '\t' << "7  - Copy" << endl;
                cout << '\t' << "0  - Quit program" << endl;
                cout << endl;
                cout << '\t' << "Selection: ";
                        cin >> num;
                cout << endl;

                if (num == 1)
                {
                        cout << "Enter an integer to add: ";
                        cin >> item;
                        try
                        {
                                queue.Enqueue(item);
                                cout << endl << item << " successfully added" << endl;
                        }
                        catch (FullQueue exceptionObject)       // error message
                        {
                                cerr << endl << "Queue is full" << endl;
                        }

                }

                else if (num == 2)
                {
                        try
                        {
                                queue.Dequeue (& item)
                                cout << endl << item << " successfully deleted" << endl;
                        }
                        catch (EmptyQueue exceptionObject)
                        {
                                cerr << endl << "Queue is empty" << endl;
                        }
                }

                else if (num == 3)
                {
                        if (queue.IsFull() == true)
                        cout << "Queue is full" << endl;
                        else
                        cout << "Queue is not full" << endl;
                }

                else if (num == 4)
                {
                        if (queue.IsEmpty() == true)
                        cout << "Queue is empty" << endl;
                        else
                        cout << "Queue is not empty" << endl;
                }

                else if (num == 5)
                {
                        queue.~QueueType();
                        cout << "Queue is now cleared";
                }

                else if (num == 6)
                {
                        queue.Print(ostream&);
                        cout << endl;
                }

                else if (num == 7)
                {
                        cout << "Old Queue" << endl;

                        cout << "New Queue" << endl;
                }

                else if (num < 0 || num > 7)
                {
                        cout << "Invalid input, please try again" << endl;
                }
}
return 0;
}

I have no idea how to implement the car wash program for this assignment, any help would be greatly appreciated