In this program, you will implement a FIFO or FCFS Queue.
The data:
1) Define a structure named Customer with four members:
CustomerName: 15-character string, which is the name of the customer
ArrivalTime: integer, which is the arrival time of the customer
ServiceTime: integer, which is the time point that the customer starts to be serviced
FinishTime: integer, which is the leaving time of the customer
2) Define a structure named FCFSQueue with two members:
CustomerList: an array of 100 elements of type Customer;
length: integer, which is the number of the customers in the queue.
This program has four functions:
1. function IsEmpty check whether the queue is empty or not. Return true if empty, otherwise return false;
2. function GetLength will returns the number of customers in the queue;
3. function Enqueue will insert a new customer to the tail of the queue;
4. function Dequeue will remove a customer from the head of the queue.
Your main program will test these functions.
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
|
#include<iostream>
#include<string>
using namespace std;
struct Customer{
string CustomerName;
int ArrivalTime;
int ServiceTime;
int FinishTime;
};
struct FCFSQueue{
Customer CustomerList[100];
int length;
};
bool IsEmpty(FCFSQueue);
int GetLength(FCFSQueue);
void Enqueue(FCFSQueue&, Customer);
void Dequeue(FCFSQueue&, Customer&);
int main()
{
FCFSQueue myQueue;
myQueue.length = 0;
Customer newCus;
newCus.CustomerName = "Tom";
newCus.ArrivalTime = 1;
newCus.ServiceTime = 0;
newCus.FinishTime = 0;
Enqueue(myQueue, newCus);
newCus.CustomerName = "Bob";
newCus.ArrivalTime = 3;
newCus.ServiceTime = 0;
newCus.FinishTime = 0;
Enqueue(myQueue, newCus);
for (int i = 0; i < myQueue.length; i++)
{
cout << myQueue.CustomerList[i] << endl;
}
Dequeue(myQueue, newCus);
Dequeue(myQueue, newCus);
Dequeue(myQueue, newCus);
}
bool IsEmpty(FCFSQueue queue)
{
if (queue.length == 0)
return true;
return false;
}
int GetLength(FCFSQueue queue)
{
return queue.length;
}
void Enqueue(FCFSQueue &queue, Customer cus)
{
if (queue.length < 100)
{
queue.CustomerList[queue.length] = cus;
++queue.length;
}
else
{
cout << "The queue is full" << endl;
}
}
void Dequeue(FCFSQueue &queue, Customer &cus)
{
if (queue.length != 0)
{
queue.CustomerList[queue.length] = cus;
--queue.length;
}
else
{
cout << "The queue is empty" << endl;
}
}
|