-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM_Money_2.cpp
45 lines (44 loc) · 1.22 KB
/
ATM_Money_2.cpp
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
#include "Bankomat_1.h"
#include <iostream>
bool Bankomat::open_bankomat(const string &pass) {
if (pass != password || open) return false;
open = true;
return true;
}
bool Bankomat::close_bankomat() {
if (!open) return false;
open = false;
return true;
}
bool Bankomat::top_up_an_ATM(map<int, int>* money) {
if (!open) return false;
map <int, int> new_bills;
for (auto el : *money){
if (bills.find(el.first) != bills.end()){
if(bills[el.first] + el.second > MAXN) return false;
else new_bills[el.first] = bills[el.first] + el.second;
}
else if (el.second > MAXN) return false;
else new_bills[el.first] = el.second;
}
for (auto el : new_bills){
bills[el.first] = el.second;
}
return true;
}
bool Bankomat::withdraw_money_from_ATM(map<int, int> *money) {
if (!open) return false;
map <int, int> new_bills;
for (auto el : *money){
if (!bills.count(el.first) || bills[el.first] < el.second){
return false;
}
else {
new_bills[el.first] = bills[el.first] - el.second;
}
}
for (auto el : new_bills) {
bills[el.first] = el.second;
}
return true;
}