-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain
More file actions
56 lines (54 loc) · 1.27 KB
/
main
File metadata and controls
56 lines (54 loc) · 1.27 KB
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
//---------------------------------------------------------
// File--------main.cpp
// Programmer--Sabera Daqiq
//
// This program computes the average time a person waits in a queue
//---------------------------------------------------------
#include <iostream>
#include <ctime>
#include <queue>
#include <stdlib.h>
#include <string>
#include "myfunc.h"
using namespace std;
int main(){
Queue s;
int id=1;
int time0;
int time1;
int time2;
int time3;
int timeA;
time3=0;
time2=0;
int count=0;
char customer;
cout<<"Customer status (A/D): ";
cin>>customer;
cout<<endl;
while ((customer!='C')&&(customer!='c')){
if (customer=='A'||customer=='a'){
time0=time(0);
s.enqueue (id,time0);
cout<<endl;
cout<<"Customer ID: "<<id<<endl;
}else if (customer=='D'||customer=='d'&&!s.isEmpty()){
time1=time(0);
s.dequeue(id, timeA);
time2=time1-timeA;
cout<<endl;
cout<<"This customer with ID "<<id<<" has waited "<<time2<<" seconds "<<endl;
count++;
time3=time3+time2;
}else if (s.isEmpty()){
cout<<"The queue is empty "<<endl;
}
cout<<endl;
cout<<"Customer status (A/D): ";
cin>>customer;
id++;
}
cout<<endl;
cout<<"The average time that the customer has waited is "<<time3/count<<" seconds"<<endl;
return 0;
}