-
Notifications
You must be signed in to change notification settings - Fork 0
/
2023-3.cpp
90 lines (85 loc) · 1.86 KB
/
2023-3.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Account {
string name;
int money;
public:
Account(string name, int money) {
this->name = name;
this->money = money;
}
string get_name() {
return name;
}
int get_money() {
return money;
}
void deposit_money(int money) {
this->money += money;
}
void withdraw_money(int money) {
this->money -= money;
}
};
class Bank {
vector<Account> user;
public:
void createAccount(Account x) {
user.push_back(x);
}
void deposit(string name, int money) {
vector<Account>::iterator it;
for (it = user.begin(); it != user.end(); it++) {
if (it->get_name() == name) {
it->deposit_money(money);
break;
}
}
}
void withdraw(string name, int money) {
vector<Account>::iterator it;
for (it = user.begin(); it != user.end(); it++) {
if (it->get_name() == name) {
it->withdraw_money(money);
break;
}
}
}
void transfer(string name1, string name2, int money) {
vector<Account>::iterator it;
for (it = user.begin(); it != user.end(); it++) {
if (it->get_name() == name1) {
it->withdraw_money(money);
break;
}
}
for (it = user.begin(); it != user.end(); it++) {
if (it->get_name() == name2) {
it->deposit_money(money);
break;
}
}
}
void print() {
vector<Account>::iterator it;
for (it = user.begin(); it != user.end(); it++) {
cout << "Account name = " << it->get_name() << ", money = " << it->get_money() << endl;
}
cout << "--------------------------------- " << endl;
cout << endl;
}
};
int main() {
Bank bank;
bank.createAccount(Account("Kim", 3000));
bank.createAccount(Account("Lee", 2000));
bank.createAccount(Account("Choi", 10000));
bank.deposit("Kim", 1000);
bank.withdraw("Lee", 1000);
bank.transfer("Choi", "Lee", 5000);
bank.print();
bank.transfer("Kim", "Choi", 3000);
bank.print();
}