-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountManagement.cpp
More file actions
165 lines (137 loc) · 2.89 KB
/
AccountManagement.cpp
File metadata and controls
165 lines (137 loc) · 2.89 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// AccountManagement.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <list>
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
#include "Account.h"
#include "PersonalAccount.h"
#include "EnterpriseAccount.h"
#include "AccountId.h"
using namespace std;
std::list<Account*> m_accountList;
int m_id = 0;
std::string GetAccountDetails(AccountId id)
{
for (std::list<Account*>::iterator it = m_accountList.begin(); it != m_accountList.end(); ++it)
{
AccountId currentId = (*it)->GetId();
if (currentId == id)
{
return (*it)->GetDetails();
}
}
return "Account not found!";
}
void ManagePersonalMenu()
{
while (true)
{
int selection;
cout << endl << " Personel Account Menu " << endl;
cout << endl << "----------------------------" << endl;
cout << "1. Create new account" << endl;
cout << "0. Back" << endl;
cin >> selection;
switch (selection)
{
case 1:
{
string firstName = "", lastName = "";
cout << "Firstname: ";
cin >> firstName;
cout << endl << "Lastname: ";
cin >> lastName;
m_accountList.push_back(new PersonalAccount(firstName, lastName, m_id++));
}
break;
case 0:
return;
default:
break;
}
}
}
void ManageEnterpriseMenu()
{
while (true)
{
int selection;
cout << endl << " Enterprise Account Menu " << endl;
cout << endl << "----------------------------" << endl;
cout << "1. Create new account" << endl;
cout << "0. Back" << endl;
cin >> selection;
switch (selection)
{
case 1:
{
string yTunnus = "", name = "";
cout << "y-tunnus: ";
cin >> yTunnus;
cout << endl << "Company name: ";
cin >> name;
m_accountList.push_back(new EnterpriseAccount(yTunnus, name, m_id++));
}
break;
case 0:
return;
default:
break;
}
}
}
void MainMenu()
{
while (true)
{
int selection;
cout << endl << " Main Menu " << endl;
cout << endl << "----------------------------" << endl;
cout << "1. Manage personal account" << endl;
cout << "2. Manage enterprise account" << endl;
cout << "3. List accounts" << endl;
cout << "4. Find account" << endl;
cout << "0. Exit" << endl;
cin >> selection;
switch (selection)
{
case 1:
ManagePersonalMenu();
break;
case 2:
ManageEnterpriseMenu();
break;
case 3:
cout << "\nAccounts" << endl;
cout << "------------------------------------------------" << endl;
std::for_each(m_accountList.begin(), m_accountList.end(), [](Account* account)
{
cout << account->GetDetails() << endl;
});
break;
case 4:
{
int id;
cout << "Give account id: ";
cin >> id;
cout << GetAccountDetails(AccountId(id)) << endl;
}
break;
case 0:
while (!m_accountList.empty())
{
delete m_accountList.front();
m_accountList.pop_front();
}
exit(0);
default:
break;
}
}
}
int main()
{
MainMenu();
}