-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWallet.cpp
More file actions
55 lines (47 loc) · 1.31 KB
/
Wallet.cpp
File metadata and controls
55 lines (47 loc) · 1.31 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
//
// Created by Luca Teodorescu on 20.03.2026.
//
#include "Wallet.h"
#include "Account.h"
#include "Bank.h"
#include <iostream>
#include <random>
#include <string>
Wallet::Wallet(Account *owner) {
this->owner = owner;
this->currency = "RON";
this->balance = 0.0;
int random_number = rand() % 900000 + 100000;
string owner_iban = owner->GetIBAN();
string iban_suffix = owner_iban.substr(owner_iban.length() - 4);
this->WalletID = "W_" + iban_suffix + "_" + to_string(random_number);
}
Wallet::Wallet(Account *owner, const string ¤cy) {
this->owner = owner;
this->currency = currency;
this->balance = 0.0;
int random_number = rand() % 900000 + 100000;
string owner_iban = owner->GetIBAN();
string iban_suffix = owner_iban.substr(owner_iban.length() - 4);
this->WalletID = "W_" + iban_suffix + "_" + to_string(random_number);
}
string Wallet::GetWalletID() {
return this->WalletID;
}
string Wallet::GetCurrency() {
return this->currency;
}
double Wallet::GetBalance() {
return this->balance;
}
void Wallet::Deposit(const double &amount) {
this->balance += amount;
}
void Wallet::Withdraw(const double &amount) {
if (this->balance < amount) {
cout << "Insufficient balance" << '\n';
}
else {
this->balance -= amount;
}
}