//I need help on where to go from here, mostly in the main.
//The instructions and requirements can be found in the attachment.

/*********************************
        Queue header file
********************************/

#ifndef QUEUE_H
#define QUEUE_H

#include <iostream>
using namespace std;

class Queue
{
private:
    class QueueNode
    {
        friend class Queue;
        int value;
        QueueNode *next;
        QueueNode(int value1, QueueNode *next1 = NULL)
        {
            value = value1;
            next = next1;
        }
    };
    QueueNode *front;
    QueueNode *rear;
public:
    Queue();
   ~Queue();

    void enqueue(int);
    void dequeue(int &);
    bool isEmpty();
    void clear();

};

#endif

/**********************************
         Queue cpp
***********************************/

#include <iostream>
#include <iomanip>

#include "queue.h"
using namespace std;

Queue::Queue ()
{
    front = NULL;
    rear = NULL;
}

Queue::~Queue()
{
    clear();
}

void Queue::enqueue(int num)
{
   if (isEmpty())
   {
       front = new QueueNode(num);
       rear = front;
   }
}

void Queue::dequeue(int &num)
{   
    QueueNode *temp;
    if (isEmpty())
    {
        cout<<"The queue is empty.\n";
        exit(1);
    }
    else
    {
        num = front->value;
        temp=front;
        front=front->next;
        delete temp;
    }
}

bool Queue::isEmpty()
{
   if (front == NULL)
       return true;
   else 
       return false;
}

void Queue::clear()
{
    int value;
    while(!isEmpty())
        dequeue(value);
}

/***************************
       main cpp
***************************/

#include <iostream>
#include <iomanip>
using namespace std;

#include <time.h>     
#include "queue.h"

int main()
{
    int option;
    Queue iQueue;
    int num = 1;

    long seconds;
    seconds = static_cast<long>(time(NULL));

    cout<<"The line is empty"<<endl;
    do {
    cout<<"Enter '1' to simulate a customer's arrival, '2' to help the next customer, or '3' to quit"<<endl;
    cin>>option;

    if (option == 1)
    {

        cout<<"Customer "<< num <<" entered the queue at time "<<seconds<<endl;
            iQueue.enqueue(num);
            num++;
    }

    else if (option == 2)
    {
        cout<<"Customer "<< num <<" is being helped at time "<<seconds<<endl;
        //cout<<"Wait time = "<<  <<"seconds "<<endl;

    }

    else 
    {
        break;
    }

    }while (option != 3);

    while (!iQueue.isEmpty())
    {
        int value;
        iQueue.dequeue(value);
        cout<<value<<" ";

    }

    system("pause");
     return 0;
}  
Attachments
Modify or rewrite the Queue class (see attachments) to simulate customer arrivals at the Department of Motor Vehicles (DMV) counter. As customers arrive, they are given a ticket number starting at 1 and incrementing with each new customer. When a customer service agent is free, the customer with the next ticket number is called. This system results in a FIFO queue of customers ordered by ticket number. Write a program that implements the queue and simulates customers entering and leaving the queue. Input into the queue should be the ticket number and a timestamp when the ticket was entered into the queue. A ticket and its corresponding timestamp is removed when a customer service agent handles the next customer. Your program should save the length of time the last three customers spent waiting in the queue. Every time a ticket is removed from the queue, update these times and output the average of the last three customers as an estimate of how long it will take until the next customer is handled. If nobody is in the queue, output that the line is empty.

Code to compute a timestamp based on the computers clock is given below. The time( NULL) function returns the number of seconds since January 1, 1970, on most implementations of C++:

#include <ctime>
...
int main()
{
long seconds;
seconds = static_ cast<long>( time( NULL));
cout<<"Seconds since 1/ 1/ 1970: "<< seconds <<endl;
return 0;
}
Sample execution is shown here:
The line is empty.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
1
Customer 1 entered the queue at time 100000044.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
1
Customer 2 entered the queue at time 100000049.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
1
Customer 3 entered the queue at time 100000055.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
2
Customer 1 is being helped at time 100000069. Wait time = 25 seconds.
The estimated wait time for customer 2 is 25 seconds.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
2
Customer 2 is being helped at time 100000076. Wait time = 27 seconds.
The estimated wait time for customer 3 is 26 seconds.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
1
Customer 4 entered the queue at time 100000080.
Enter ' 1' to simulate a customer's arrival, ' 2' to help the next customer, or ' 3' to quit.
2
Customer 3 is being helped at time 100000099. Wait time = 44 seconds.
The estimated wait time for customer 4 is 32 seconds.

Customers need to be numbered and put in waiting room status, and then as windows are free, assigned to windows sequentially. One behavior is the number and add to tail (take a ticket), and the other is to read and delete from head (now serving #N). Now, the waiting room could be any container type, or just a pair of counters, the input counter (ticket roll) and the output counter (now serving display). Containers would be overkill, until you grow more requirements.

This article has been dead for over six months. Start a new discussion instead.