-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
114 lines (94 loc) · 3.12 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
class BankingSystem {
private:
double accountBalance;
double interestRate;
std::vector<std::string> transactionHistory;
public:
// Constructor
BankingSystem() : accountBalance(0), interestRate(0.05) {}
// Public Methods
void startOperation() {
int choice;
double amount;
while (true) {
std::cout << "Select an operation:\n"
<< "1. Deposit\n"
<< "2. Withdraw\n"
<< "3. Check Account Balance\n"
<< "4. View Transaction History\n"
<< "5. Cancel Operation\n"
<< "Enter Your Choice: ";
std::cin >> choice;
switch (choice) {
case 1:
std::cout << "Enter amount: ";
std::cin >> amount;
deposit(amount);
break;
case 2:
std::cout << "Enter amount: ";
std::cin >> amount;
withdraw(amount);
break;
case 3:
showBalance();
break;
case 4:
viewTransactionHistory();
break;
case 5:
cancel();
return;
default:
std::cerr << "Invalid choice. Please enter a valid option.\n";
}
}
}
private:
// Private Methods
void deposit(double amount) {
accountBalance += amount;
addToTransactionHistory("Deposit: +" + std::to_string(amount));
applyInterest();
std::cout << "Your money is deposited.\n";
}
void withdraw(double amount) {
if (amount > accountBalance) {
std::cerr << "Insufficient funds.\n";
return;
}
accountBalance -= amount;
addToTransactionHistory("Withdrawal: -" + std::to_string(amount));
applyInterest();
std::cout << "Withdrawal successful.\n";
}
void showBalance() {
std::cout << "Your account balance is: $" << std::fixed << std::setprecision(2) << accountBalance << "\n";
}
void cancel() {
std::cout << "Thank you for using our bank. Have a nice day!\n";
}
void viewTransactionHistory() {
std::cout << "Transaction History:\n";
for (const auto& transaction : transactionHistory) {
std::cout << transaction << "\n";
}
}
void applyInterest() {
double interest = accountBalance * interestRate;
accountBalance += interest;
addToTransactionHistory("Interest Applied: +" + std::to_string(interest));
}
void addToTransactionHistory(const std::string& transaction) {
transactionHistory.push_back(transaction);
}
};
int main() {
BankingSystem bankingSystem;
bankingSystem.startOperation();
return 0;
}