-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
233 lines (216 loc) · 8.83 KB
/
main.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
class Person {
private:
std::string name;
int account_number;
double balance;
public:
//constructor overload
Person(){
}
Person(std::string n, int acc_num, double bal = 0)
: name(n), account_number(acc_num), balance(bal)
{
}
//Destructor
~Person(){
}
//getters
std::string get_name(){
return name;
}
int get_acc_num(){
return account_number;
}
double get_bal(){
return balance;
}
void set_bal(double amount, std::string d_w){
if(d_w == "deposit"){
balance += amount;
std::cout << "==============Deposit was successful=================" << std::endl;
std::cout << "Account balance is " << get_bal() << std::endl;
std::cout << std::endl;
} else if(d_w == "withdrawal"){
balance -= amount;
std::cout << "==============Withdrawal was successful=================" << std::endl;
std::cout << "Account balance is " << get_bal() << std::endl;
std::cout << std::endl;
}
}
void print(){
std::cout << std::endl;
std::cout << "==========Account Details==========" << std::endl;
std::cout << "Account Num: " << account_number << std::endl;
std::cout << "name: " << name << std::endl;
std::cout << "Balance: " << balance << std::endl;
}
//deposit money into account
double deposit(){
std::cout << std::endl;
std::cout << "==========Deposit==========" << std::endl;
std::cout << "How much would you like to Deposit? ";
double dep{};
std::cin >> dep;
return dep;
}
double withdrawal(){
std::cout << std::endl;
std::cout << "==========Withdrawal==========" << std::endl;
std::cout << "How much would you like to Withdraw? ";
double dep{};
std::cin >> dep;
return dep;
}
};
Person null_person;
class Account {
private:
std::vector<Person> list_acc;
//Person p;
public:
//create new Account and Using the person class to create new person
void new_account(int acc_num, std::string n, double dep = 0){
Person p(n, acc_num, dep);
list_acc.push_back(p);
std::cout << std::endl;
std::cout << "==========Account was Created Successfully==========" << std::endl;
p.print();
}
//print all accounts
void print_all_acc(){
if(list_acc.size() > 0){
for(auto i : list_acc){
std::cout << "==============================" << std::endl;
std::cout << "Account Number: " << i.get_acc_num() << std::endl;
std::cout << "Name: " << i.get_name() << std::endl;
std::cout << "Balance: " << i.get_bal() << std::endl;
std::cout << "==============================" << std::endl;
}
} else {
std::cout << "There are no accounts in the List" << std::endl;
}
}
//this is not working right
Person& find_acc(int id){
for(Person& i : list_acc){
if(id == i.get_acc_num()){
std::cout << i.get_name() << std::endl;
std::cout << i.get_bal() << std::endl;
return i;
}
}
return null_person; //problem here,
}
};
class Menu {
public:
Account a;
Person p;
//the menu
void menu(){
std::cout << std::endl;
std::cout << "==========Menu==========" << std::endl;
std::cout << "1. Create Account" << std::endl;
std::cout << "2. Print List of Accounts" << std::endl;
std::cout << "3. Deposit into Account" << std::endl;
std::cout << "4. Withdrawal from Account" << std::endl;
}
//menu choices based on input
void menu_choice(char &input){
std::cout << std::endl;
std::cout << "Please make a Choice or press e to exit: ";
std::cin >> input;
switch(input){
case '1': {
std::cout << std::endl;
std::cout << "==============Creating an Account===============" << std::endl;
std::cout << "Enter your name: ";
std::string name;
std::cin.ignore();
std::getline(std::cin, name);
int account_number = rand() % 100 + 1; //gets random number for account
/*
std::cout << "Checking or Savings?(C/S)?";
if(input == 's' || input == 'S'){
p.savings_acc();
} else if(input == 'c' || input == 'C'){
p.checkings_acc()
}*/
std::cout << "Would you like to deposit?(Y/N) ";
double deposit_amount{};
char input{};
std::cin >> input;
if(input == 'y' || input == 'Y'){
deposit_amount = p.deposit();
}
a.new_account(account_number, name, deposit_amount);
std::cout << "================================================" << std::endl;
break;
}
case '2': {
std::cout << std::endl;
std::cout << "=================List of Accounts=============" << std::endl;
a.print_all_acc();
std::cout << "==============================================" << std::endl;
break;
}
case '3': {
std::cout << std::endl;
std::cout << "==============Deposit into Account=============" << std::endl;
std::cout << "Enter your Account ID: ";
int input{};
std::cin >> input;
Person &p = a.find_acc(input);
if(p.get_acc_num() == 0){
std::cout << "Account does not exists" << std::endl;
break;
} else {
double new_amount{};
new_amount = p.deposit();
p.set_bal(new_amount, "deposit");
break;
}
}
case '4': {
std::cout << std::endl;
std::cout << "==============Withdrawal from Account=============" << std::endl;
std::cout << "Enter your Account ID: ";
int input{};
std::cin >> input;
Person &p = a.find_acc(input);
if(p.get_acc_num() == 0){
std::cout << "Account does not exists" << std::endl;
break;
} else {
double withdrawal_amount{};
withdrawal_amount = p.withdrawal();
p.set_bal(withdrawal_amount, "withdrawal");
break;
}
}
default: {
if(input == 'e'){
std::cout << "Goodbye" << std::endl;
} else{
std::cout << "please choose or exit" << std::endl;
}
break;
}
}
}
};
int main() {
Menu m;
char input{};
srand(time(NULL));
do{
m.menu();
m.menu_choice(input);
} while(input != 'e');
return 0;
}