QUEUE program

I need help with my program.
It will not recognize whether or not a customer has arrived.
I have a feeling that the timer isn't working either.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Queue.h"
#include <cstdlib>
#include <ctime>

void main()
// Description: main entry point of program
//  Parameters: none
//     Returns: nothing
{
	Queue<int> checkout;
	
	srand(time(0)); // random number gen

	int timer = 0;
	int start = rand() % 4 + 1;
	int service = 0;
	int next = 0;
	int maxQ = 0;
	int maxW = 0;
	int temp = 0;

	while(timer < 50)
	{
		cout << endl << "Time : " << timer+1 << " : Actions for this time" << endl;
		if (timer == start)
		{
			service = rand() % 4 + 1;
			next = rand() % 4 + 1 + timer;
			checkout.enQueue(timer);
		}
		else if (timer == next)
		{
			cout << "Customer just arrived." << endl;
			checkout.enQueue(timer);
			next = rand() % 4 + 1 + timer;
		}

		if (service == 0)
		{
			cout << "Customer finished." << endl;
			service = rand() % 4 + 1;
			checkout.deQueue(temp);
			if (temp > maxW)
				maxW = temp;
		}
		if (checkout.getQueue() > maxQ)
			maxQ = checkout.getQueue();
		next--;
		service--;
		temp++;
		timer++;	
	} // end while
}


Here is my problem:
1) Choose a random integer between 1 and 4 to determine the minute at which the first customer arrives.

2) At the first customer's arrival time;
*Determine customer's service time (random integer 1 to 4)
*Begin Servicing the customer;
*Schedule arrival time of the next customer (random integer 1 to 4 added to the current time)

3) For each minute of the day:
*If the customer arrives;
- say so, enqueue the customer;
- schedule the arrival time of the next customer;
*If service was completed for the last customer;
- say so,
- dequeue next customer to be serviced
- determine customers completion time (random integer from 1 to 4 o the current time)


Correct me if i'm wrong, but my program SHOULD be doing that. yet it only shows the first customer arriving.
Last edited on
"Queue.h"?
"Queue.h"?!?

Why not use an STL deque?

This post is prone to editing.

Could we get a copy of "Queue.h"'s documentation?

You beat me to it.

-Albatross
Last edited on
this is what
Queue.h
consists of.
This is for my programming class. We have too many kids in my class for my instructor to help me.

So you can see my problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef QUEUE_H
#define QUEUE_H

#include "List.h"

template <typename QUEUETYPE>
class Queue : private List<QUEUETYPE>
{
public :
	void enQueue(const QUEUETYPE &data)
	{
		if (isEmpty())
			queueCount = 0;
		else
			queueCount++;
		insertAtBack(data);
	}
	bool deQueue(QUEUETYPE &data)
	{
		if(isEmpty())
			queueCount = 0;
		else
			queueCount--;
		return removeAtFront(data);
	}
	bool isQueueEmpty() const
	{
		return isEmpty();
	}
	void printQueue() const
	{
		print();
	}
	int getQueue()
	{
		return queueCount;
	}
private:
	int queueCount;
};

#endif 
Last edited on
If you're allowed to use deque or a plain list, I suggest you do use it. Easier management of stuff that goes into it...

And in that queue, I'd put the time it takes for the service for the customer at the top of the deque to be completed.

Hope that helps.

-Albatross
Alright, i fixed it. It works now. thank you for the help. here is the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Queue.h"
#include <cstdlib>
#include <ctime>

void main()
// Description: main entry point of program
//  Parameters: none
//     Returns: nothing
{
	Queue<int> checkout;
	
	srand(time(0)); // random number gen

	int timer = 0;
	int start = rand() % 4 + 1;
	int service = start;
	int next = rand() % 4 + 1 + timer + start;
	int maxQ = 0;
	int maxW = 0;
	int temp = 0;
	int temp1 = 0;

	while(timer < 720)
	{
		cout << endl << "Time : " << timer+1 << " : Actions for this time" << endl;
		if (timer == start)
		{
			cout << "First Customer." ;
			service = rand() % 4 + 1;
			cout << " Service Time: " << service << endl;
			next = rand() % 4 + 1 + timer;
			checkout.enQueue(timer);
		}
		else if (timer == next)
		{
			cout << "Customer arrived.";
			checkout.enQueue(timer);
			next = rand() % 4 + 1 + timer;
			cout << " Wait Time: " << next-timer << endl;
		}

		if (service == 0)
		{
			cout << "Customer finished.";
			service = rand() % 4 + 1;
			cout << " Service Time: " << service << endl;
			checkout.deQueue(temp);
			temp1 = temp;
			if (temp1 > maxW)
				maxW = temp1;
		}
		if (checkout.getQueue() > maxQ)
			maxQ = checkout.getQueue();
		service--;
		temp++;
		timer++;	
	} // end while

	cout << endl;

	cout << "All customers in-line are now kicked out!" << endl;
	cout << "Longest wait: " << timer-maxW << endl;
	cout << "Most Customers in line: " << maxQ << endl;

	cout << endl;
}


Here is a bit of the finished product.



Time : 710 : Actions for this time
Customer arrived. Wait Time: 4

Time : 711 : Actions for this time

Time : 712 : Actions for this time

Time : 713 : Actions for this time
Customer finished. Service Time: 4

Time : 714 : Actions for this time
Customer arrived. Wait Time: 2

Time : 715 : Actions for this time

Time : 716 : Actions for this time
Customer arrived. Wait Time: 3

Time : 717 : Actions for this time
Customer finished. Service Time: 4

Time : 718 : Actions for this time

Time : 719 : Actions for this time

Time : 720 : Actions for this time

All customers in-line are now kicked out!
Longest wait: 20
Most Customers in line: 11

Destroying nodes...
All nodes destroyed!
Press any key to continue . . .


-JonnyCode
Topic archived. No new replies allowed.