-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.cpp
More file actions
109 lines (100 loc) · 2.85 KB
/
Copy pathmanager.cpp
File metadata and controls
109 lines (100 loc) · 2.85 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "manager.h"
Manager::Manager()
{
}
void Manager::AddToQueue(string file_name)
{
ifstream in_file;
in_file.open(file_name);
while (!in_file.eof())
{
Transaction* t = new Transaction();
in_file >> *t;
//cout << *t << endl;
transaction_queue.push(*t);
}
in_file.close();
}
void Manager::PopQueue()
{
while (!transaction_queue.empty())
{
Transaction* current_transaction = &transaction_queue.front();
if (current_transaction->type() == 'O')
{
Account* temp;
if (account_list_.Retrieve(current_transaction->id(), temp))
{
cerr << "ERROR: Account " << current_transaction->id() << " is already open.Transaction refused." << endl;
}
else
{
Account* insert_account = new Account(*current_transaction);
account_list_.Insert(insert_account);
}
}
else if (current_transaction->type() == 'W')
{
Account* temp;
if (!account_list_.Retrieve(current_transaction->id(), temp))
{
cerr << "ERROR: Account " << current_transaction->id() <<" not found. Withdrawal refused." << endl;
}
else
{
if (!temp->Transact(*current_transaction))
{
cerr << "ERROR: Not enough funds to withdraw " << current_transaction->ammount() << " from fund " <<current_transaction->fund() << " of account #" << current_transaction->id() << "." << endl;
}
}
}
else if (current_transaction->type() == 'D')
{
Account* temp;
if (!account_list_.Retrieve(current_transaction->id(), temp))
{
cerr << "ERROR: Account " << current_transaction->id() << " not found. Deposit refused." << endl;
}
else
{
temp->Transact(*current_transaction);
}
}
else if (current_transaction->type() == 'T')
{
Account* temp1;
Account* temp2;
if (!account_list_.Retrieve(current_transaction->id1(), temp1))
{
cerr << "ERROR: Account " << current_transaction->id1() << " not found. Transfer refused." << endl;
}
else if (!account_list_.Retrieve(current_transaction->id2(), temp2))
{
cerr << "ERROR: Account " << current_transaction->id2() << " not found. Transfer refused." << endl;
}
else
{
if (!temp1->Transact(*current_transaction))
{
cerr << "ERROR: Not enough funds to transfer " << current_transaction->ammount() << " from fund " << current_transaction->fund1() << " of account #" << current_transaction->id1() << "." << endl;
}
temp2->Transact(*current_transaction);
}
}
else
{
Account* temp;
if (!account_list_.Retrieve(current_transaction->id(), temp))
{
cerr << "ERROR: Account " << current_transaction->id() << " not found. History refused." << endl;
}
else
{
temp->Transact(*current_transaction);
}
}
transaction_queue.pop();
}
cout << "FINAL BALANCES:" << endl;
account_list_.Display();
}