-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenMachine.cpp
More file actions
62 lines (62 loc) · 1.66 KB
/
TokenMachine.cpp
File metadata and controls
62 lines (62 loc) · 1.66 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
57
58
59
60
61
62
#include<iostream>
#include"String.h"
#include"TokenMachine.h"
using namespace std;
unsigned int TokenMachine::_tokenNumber = 0;
const unsigned int TokenMachine::_MAX_LIVE_TOKENS = TokenMachine::setMaxLiveTokens();
const double TokenMachine::_AVERAGE_PROCESSING_TIME_IN_MINUTES = TokenMachine::setAverageProcessingTime();
unsigned int TokenMachine::_activeTokens = 0;
int TokenMachine::setMaxLiveTokens(int num )
{
return num;
}
double TokenMachine::setAverageProcessingTime(double tm )
{
return tm;
}
String TokenMachine::getNextToken()
{
if(_activeTokens < _MAX_LIVE_TOKENS)
{
_tokenNumber++;
String str{ "Token Id: " };
String token;
token.setNumber(_tokenNumber);
str.concatEqual(token);
String activeMemberMessage{ "\nPerson before you in Line are: \nExpected Waiting Time: minutes" };
activeMemberMessage.at(32) = (char)(getActiveTokensCount() + 48);
token.setNumber(_AVERAGE_PROCESSING_TIME_IN_MINUTES*_activeTokens);
activeMemberMessage.insert(57, token);
str.concatEqual(activeMemberMessage);
_activeTokens++;
return str;
}
else
{
String temp;
temp.setNumber(_MAX_LIVE_TOKENS);
String str{ "We are sorry. There can't be more than tokens in system for service. Please wait for some clients to get serviced" };
str.insert(39,temp);
return str;
}
}
unsigned int TokenMachine :: getActiveTokensCount()
{
return _activeTokens;
}
void TokenMachine::personIsServiced()
{
if (_activeTokens > 0)
{
_activeTokens--;
}
}
unsigned int TokenMachine::getCountOfPersonsServiced()
{
return _tokenNumber-_activeTokens;
}
void TokenMachine::resetMachine()
{
_tokenNumber = 0;
_activeTokens = 0;
}