-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.cpp
More file actions
135 lines (114 loc) · 4.54 KB
/
customer.cpp
File metadata and controls
135 lines (114 loc) · 4.54 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include"customer.h"
customer::customer(){
account_number = 0;
customer_name = "";
customer_password = "";
balance = 0.0;
loan_amount = 0.0;
password_attempts_remaining = 0;
account_status = 0;
}
customer::customer(long acc_no, std::string name, std::string passwd, double bal, double loan_bal, int attempts, int status){
account_number = acc_no;
customer_name = name;
customer_password = passwd;
balance = bal;
loan_amount = loan_bal;
password_attempts_remaining = attempts;
account_status = status;
}
void customer::withdraw(const AppConfig& config){
double amount;
std::cout<< "Enter The Amount of Money to Withdraw: ";
std::cin>> amount;
this->withdraw(amount, config, false);
}
bool customer::withdraw(double amount, const AppConfig& config, bool silent){
if(amount<0) {std::cout<<"Negative Money !!"; return false;}
if(balance >= amount){
balance -= amount;
if(!silent) std::cout << "Transaction Successful.\n";
if(balance < config.minimum_balance){
balance -= config.minimum_balance_charge;
if(!silent) std::cout << "Balance is below minimum. A charge of " << config.minimum_balance_charge << " has been deducted.\n";
}
return true;
} else {
if(!silent) std::cout << "Transaction Failed: Insufficient Funds.\n";
return false;
}
}
void customer::deposit(){
double amount;
std::cout<< "Enter The Amount of Money to Deposit: ";
std::cin>> amount;
this->deposit(amount,false);
}
bool customer::deposit(double amount, bool silent){
if(amount<0) {std::cout<<"Negative Money !!"; return false;}
balance += amount;
if(!silent) std::cout << "Transaction Successful.\n";
return true;
}
void customer::transfer(std::vector<customer>& all_customers, const AppConfig& config){
long receiver_account_no;
double amount;
std::cout<<"Enter the Account Number to Transfer Funds: ";
std::cin>> receiver_account_no;
std::cout<< "Enter The Amount of Money to Transfer: ";
std::cin>> amount;
customer *receiver = nullptr;
for(customer &user: all_customers){
if(user.get_account_number() == receiver_account_no){
receiver = &user;
break;
}
}
if(receiver != nullptr){
// Only deposit if the withdrawal from this account succeeds
if(this->withdraw(amount, config, false)){
receiver->deposit(amount, false);
std::cout << "Transfer to account " << receiver_account_no << " was successful.\n";
}
} else {
std::cout << "Error: Receiver account not found.\n";
}
}
void customer::change_password(){
std::string new_password;
std::cout<<"Choose a New Password: \n";
std::cout<<"NOTE: CHOOSE A STRONG PASSWORD!!!\n";
std::cin>>new_password;
customer_password = encrypt(new_password);
std::cout<< "Password Updated Successfully.\n";
}
void customer::view_balance(){
std::cout<<"Your Current Balance is: "<< balance<< std::endl;
std::cout<<"You Have Loan Due of: "<< loan_amount;
}
void customer::pay_loan(const AppConfig& config){
std::cout<<"The Amount Will be Deducted from your Account.\n";
double amount;
std::cout<< "Enter The Amount of Money to Pay Loan: ";
std::cin>> amount;
if(amount<0) {std::cout<<"Negative Money !!"; return;}
if(amount>loan_amount) {std::cout<<"You Don't have that much Due"; return;}
if (this->withdraw(amount, config, true)) {
this->edit_loan_amount(this->get_loan_amount() - amount);
std::cout << "Loan payment of Rs." << amount << " was successful.\n";
std::cout << "Remaining Loan Due: Rs." << this->get_loan_amount() << std::endl;
}
}
long customer::get_account_number() const { return account_number; }
std::string customer::get_customer_name() const { return customer_name; }
std::string customer::get_password() const { return customer_password; }
double customer::get_balance() const { return balance; }
double customer::get_loan_amount() const { return loan_amount; }
int customer::get_password_attempts_remaining() const { return password_attempts_remaining; }
int customer::get_account_status() const { return account_status; }
void customer::edit_account_status(int status) { account_status = status; }
void customer::edit_password_attempts_remaining(int attempts) { password_attempts_remaining = attempts; }
void customer::edit_loan_amount(double loan) { loan_amount = loan; }
std::string encrypt(std::string &passwd){
return std::to_string(std::hash<std::string>{}(passwd));
}