-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.cpp
More file actions
121 lines (106 loc) · 3.57 KB
/
User.cpp
File metadata and controls
121 lines (106 loc) · 3.57 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
#include <iostream>
#include "User.h"
#include "Invest.h"
using namespace std;
int User::active_users = 0; // Number of user created
User::User(string name, double bank, double wallet){ // Constructor - give a value to the members of the User
this->name = name;
this->bank_account = bank;
this->wallet = wallet;
this->debt = 0;
++active_users;
};
User::~User() { // Destructor - eliminate the User
--active_users;
}
void User::depositMoney(double depositedMoney) { // method that deposit money
if ((wallet-depositedMoney)<=0) {
cout << "il deposito di denaro viene annullato\n";
cout << "Non si ha abbastanza soldi nel portafoglio\n";
return;
}
wallet -= depositedMoney;
bank_account += depositedMoney;
cout << "Nella banca viene depositato una somma di " << depositedMoney << " euro\n";
}
void User::withdrawMoney(double takenMoney) { // method that withdraw money
if ((bank_account - takenMoney) <= 0) {
cout << "il prelievo di denaro viene annullato\n";
cout << "Non si puo prelevare da un conto in banca in debito o a zero\n";
return;
}
wallet += takenMoney;
bank_account -= takenMoney;
cout << "Nella banca viene prelevato una somma di " << takenMoney << " euro\n";
}
void User::bankState() { // method that shows you your bank state
cout << "La somma del capitale che si trova in banca corrisponde a " << bank_account << " euro\n";
}
void User::walletState() { // method that shows you your wallet state
cout << "La somma dei soldi in contatti che si trovano nel portafoglio corrisponde a " << wallet << " euro\n";
}
void User::getInvestment(Investment new_invest) { // method that creates you an investment
srand(time(NULL));
double earning{ 0 };
char level_risk {' '};
if (bank_account < new_invest.getAmount()) {
cout << "Non si ha abbastanza soldi\n";
return;
}
bank_account -= new_invest.getAmount();
cout << "Viene prelevato dalla banca " << new_invest.getAmount() << " euro per fare l'investimento\n";
if (new_invest.getRisk() <= 3)
level_risk = '-'; // Low risk with little revenue
else if (new_invest.getRisk() > 3 && new_invest.getRisk() <= 7)
level_risk = '='; // Medium risk with medium revenue
else if (new_invest.getRisk() > 7)
level_risk = '+'; // High risk with big revenue
for (int i{ 0 };i < new_invest.getDuration(); i++){
if (debt > 0) {
if (i==0) {
if (bank_account >= debt) {
bank_account -= debt;
debt = 0;
}
else {
debt -= bank_account;
bank_account = 0;
}
}
else {
if (earning >= debt) {
earning -= debt;
debt = 0;
}
else {
debt -= earning;
earning = 0;
}
}
}
else {
if (level_risk == '-') {
earning += static_cast<double>(rand() % 9900 + 100);
debt += static_cast<double>(rand() % 2000 + 50);
}
else if (level_risk == '=') {
earning += static_cast<double>(rand() % 99000 + 500);
debt += static_cast<double>(rand() % 20000 + 225);
}
else if (level_risk == '+') {
earning += static_cast<double>(rand() % 999000 + 1000);
debt += static_cast<double>(rand() % 750000 + 25000);
}
}
increaseMonths(new_invest.getDuration());
}
earning -= debt;
debt = 0;
bank_account += earning;
new_invest.~Investment();
}
void User::increaseMonths(int months) { // method that make pass time
for (int i{ 0 }; i < months; i++) {
wallet += 100;
}
}