-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.cpp
More file actions
82 lines (73 loc) · 2.25 KB
/
Account.cpp
File metadata and controls
82 lines (73 loc) · 2.25 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
//
// Created by Luca Teodorescu on 20.03.2026.
//
#include "Account.h"
#include "Wallet.h"
#include <iostream>
#include <string>
#include <random>
Account::Account(User *account_owner) {
this->owner = account_owner;
string birth_date = account_owner->GetBirthDate();
int random_number = rand() % 900000 + 100000;
this->IBAN = "RO" + birth_date + "BANK" + to_string(random_number);
Wallet* default_wallet = new Wallet(this);
string WalletID = default_wallet->GetWalletID();
if (!AllWallets.contains(WalletID)) {
AllWallets[WalletID] = default_wallet;
}
else {
delete default_wallet;
cout << "Eroare: Portofel cu ID duplicat!" << '\n';
}
}
Account::Account(User *account_owner, const string ¤cy) {
this->owner = account_owner;
string birth_date = account_owner->GetBirthDate();
int random_number = rand() % 900000 + 100000;
this->IBAN = "RO" + birth_date + "BANK" + to_string(random_number);
Wallet* default_wallet = new Wallet(this, currency);
string WalletID = default_wallet->GetWalletID();
if (!AllWallets.contains(WalletID)) {
AllWallets[WalletID] = default_wallet;
}
else {
delete default_wallet;
cout << "Eroare: Portofel cu ID duplicat!" << '\n';
}
}
string Account::GetIBAN() {
return this->IBAN;
}
void Account::addWallet() {
Wallet *new_wallet = new Wallet(this);
string WalletID = new_wallet->GetWalletID();
if (AllWallets.find(WalletID) != AllWallets.end()) {
AllWallets[WalletID] = new_wallet;
}
}
void Account::DeleteWallet() {
AllWallets.clear();
}
void Account::DeleteWallet(const string &WalletID) {
auto it = AllWallets.find(WalletID);
if (it != AllWallets.end()) {
delete it->second;
AllWallets.erase(it);
cout << "Portofelul cu ID-ul " << WalletID << " a fost sters cu succes.\n";
}
else {
cout << "Eroare: Portofelul cu ID-ul " << WalletID << " nu a fost gasit in acest cont!\n";
}
}
Wallet *Account::GetWallet(const string &WalletID) {
if (AllWallets.find(WalletID) != AllWallets.end()) {
return AllWallets[WalletID];
}
}
Account::~Account() {
for (auto &it : AllWallets) {
delete it.second;
}
AllWallets.clear();
}