The Problem : Simulation of Waiting Queue

I have this Problem as an assignment :
An airport has one runway. When a plane arrives near the airport at a random time Tarrival, it might have to wait (remain airborne) in a landing queue a time Twait until the runway becomes free and ready to receive it. Once a plane lands on the beginning of the runway, the runway becomes occupied for a fixed time Tlanding until the plane docks (This is the service time).
Develop a program to simulate the airport operation with the objective of computing the average wait time in the landing queue and the average number of planes waiting in the queue.
Assume the following:
• The time (clock) unit is one minute
• A fixed simulation period Tmax
• A fixed time Tlanding to complete landing.
• A random arrival time Tarrival with a fixed average inter-arrival time T
You might start your simulation using a “standard run” with:
Tmax = 6 hours, Tlanding = 6 minutes, T = 4 minutes
After that, you might investigate the effect of varying arrival rates to simulate prime and slack times of the day, or if the amount of time to complete landing is changed.
Allow your program to produce a “log” of the events of arrival and landing in each run.
Allow another queue to represent planes waiting to take off from the same runway. Because it is more expensive to wait airborne, planes in the landing queue have priority over those in the take off queue. When the runway becomes free, check if the landing queue is nonempty and if so allow the plane to land, otherwise consider the take off queue. Consider that for take off, Ttakeoff = 10 minutes, T = 4 minutes.

And I am working on it, but I struggling with code as usual. I think I am getting a lot of things wrong :(

So here is my header file:
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
/ File: Queuet.h
// Queue template class definition
// Dynamic array implementation 

#ifndef QUEUET_H           
#define QUEUET_H

template <class Type>          

class Queuet
{
   public:
	        
      Queuet(int nelements = 128);		// Constructor
	  Queuet (const Queuet <Type> &);	// Copy Constructor
      ~Queuet();						// Destructor

	  // Member Functions
      void enqueue(Type );			// Add to rear
	  void dequeue(Type &);			// Remove from front
	  void queueFront(Type &) const;	// retrieve front
      bool queueIsEmpty() const;	// Test for Empty queue
      bool queueIsFull() const;		// Test for Full queue
	  int  queueLength() const;		// Queue Length
      
   private:
      Type *queue;					// pointer to dynamic array
	  int front, rear, count, MaxSize;

}; 

#endif // QUEUET_H
#include "Queuet.cpp" 


and here is the cpp file of the queues:
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
67
68
69
70
71
72
73
74
75
/ File: Queuet.cpp
// Queue template class implementation

#include <iostream>
using namespace std;


// Constructor with argument, size is nelements, default 128
template <class Type>
Queuet<Type>::Queuet(int nelements)   
{  MaxSize = nelements; queue = new Type[MaxSize]; 
   front = 1; rear = 0; count = 0; 
}  

// Copy Constructor
template <class Type>
Queuet<Type>::Queuet (const Queuet<Type> &original)
 :MaxSize(original.MaxSize), front(original.front), rear(original.rear), count(original.count) 
	{
		queue = new Type[MaxSize];
		for (int i = 0; i < MaxSize; i++) queue[i] = original.queue[i];
	 }


// Destructor
template <class Type>
Queuet<Type>::~Queuet()
{ delete [] queue;}

// Add to rear
template <class Type>
void Queuet<Type>::enqueue(Type v)
{ 
	if(queueIsFull()) cout << "Queue is Full" << endl; 
	else 
	{
		rear = (rear + 1) % MaxSize;
		queue[rear] = v;  count++;
	}
}

// Remove from front
template <class Type>
void Queuet<Type>::dequeue(Type &v)
{
	if(queueIsEmpty()) cout << "Queue is Empty" << endl; 
	else 
	{
		v = queue[front];
		front = (front + 1) % MaxSize; count--;
	}
}

// Retrieve front without removing it
template <class Type>
void Queuet<Type>::queueFront(Type &v) const
{
	if(queueIsEmpty()) cout << "Queue is Empty" << endl; 
		else 	v = queue[front];
}

// Test for Empty queue
template <class Type>
bool Queuet<Type>::queueIsEmpty() const
{ return (count == 0); }

// Test for Full queue
template <class Type>
bool Queuet<Type>::queueIsFull() const
{ return (count == MaxSize); }

// Queue Length
template <class Type>
int Queuet<Type>::queueLength() const
{ return count; }


And that here is my source code of the 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include<time.h>
#include <cstdlib>
#include "Queuet.h"
using namespace std;

//-------------------------------------

int Tmax;
int Ta;
int Ts;
int Tr=0;
int T;
int jobcount=0;
int waitTotal=0;
int Tw;
float Pa=1/Ta;
//--------------------------------------------
void arrival(Queuet <int>&);
float avergaewait(Queuet <int>&);
void ready_server(Queuet <int>&);
void ExitLine(Queuet <int> &);






int main()

{
	srand((unsigned)time(NULL));
	Tr=0;
	cout<<"**Welcome**"<<endl;
	cout<<"Do you want to save default settings or change simulation period, landing time, and average inter-arrival time? Y for yes and N for No"<<endl;
		char answer;//take the answer from the user
		cin>>answer;

	if((answer=='y')||(answer=='Y'))//if he answers Yes then changes the default settings to his settings

	{
		cout<<"Please enter the simulation period :";
			int A;
			cin>>A;
			Tmax=A;
			cout<<"Please enter the landing time :";
			int B;
			cin>>B;
			Ts=B;
			cout<<"Please enter the  average inter-arrival time :";
			int C;
			cin>>C;
			Ta=C;

	}
	else //else keep the defaukt settings as they are
	{
	 
		Ta=4;
		Ts=6;
		Tmax=360;
	}

	Queuet<int> Q;//landing queue

	int T=0;//set time to 0

	while(T<Tmax)// as long as time didnot exced maximum time

	{
		arrival(Q);
		ready_server(Q);
		if(Tr>0)
			Tr--;
		T++;
		float avg=avergaewait(Q);
	}
	

	return 0;

}



I am sure there are many errors within the code and I have been working on it all night, so if you please tke a look at code and tell me what is wrong with it, that would be great.
Thanks in Advance
Last edited on
Topic archived. No new replies allowed.