This repository was archived by the owner on Aug 24, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathatm.cpp
More file actions
203 lines (165 loc) · 5.24 KB
/
Copy pathatm.cpp
File metadata and controls
203 lines (165 loc) · 5.24 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
This project is based on the logic of a typical atm machine
Account number is set as 55555
Pin number is set as 99999
*/
#include <iostream>
using namespace std;
class Account
{
private:
int acnumber = 55555; //account number of customer
int pinNumber = 99999; //pin number of customer
int AccountBalance = 0; //default account balance
public:
bool CheckCustomerDetails();
int MenuDisplay();
void DisplayAccountBalance();
void WithdrawMoney();
void DepositMoney();
};
bool Account::CheckCustomerDetails() {
int InputAccountNumber = -1;
int InputPinNumber = -1;
bool isAccountInvalid = true;
bool isPinInvalid = true;
cout << "Welcome!" << endl;
while (isAccountInvalid) {
cout << "Please enter your Bank account number: ";
cin >> InputAccountNumber;
if (InputAccountNumber == acnumber) {
isAccountInvalid = false;
}
else {
cout << "Invalid Account Number! Try again." << endl;
}
}
int RetryCount = 3;
while (isPinInvalid && RetryCount) {
cout << "Enter your PIN: ";
cin >> InputPinNumber;
if (InputPinNumber == pinNumber) {
isPinInvalid = false;
}
else {
RetryCount--;
if(RetryCount)
cout << "Invalid Customer PIN number! Try again." << endl;
else
{
cout << "Your Account is Locked! 3 retry Reached! Try After some time." << endl;
return false;
}
}
}
return true;
}
int Account::MenuDisplay() {
// to display the menu to the customer and return the input value to main function
int UserInputOption = -1;
cout << "Welcome to Your Account!! Please choose Option to Proceed" << endl;
cout << " 1 - View Your Account balance" << endl;
cout << " 2 - Withdraw Money (cash)" << endl;
cout << " 3 - Deposit Money (cash)" << endl;
cout << " 4 - Exit" << endl;
cout << "Enter an Option to Proceed: " << endl;
cin >> UserInputOption;
return UserInputOption;
}
void Account::DisplayAccountBalance() {
// function of class Account (to display account balance)
cout << "You Account Balance is:" << endl;
cout << "Rupees " << AccountBalance << endl;
}
void Account::WithdrawMoney() {
// function of class Account (to withdraw money from account)
int valueToWithdraw = 0;
long CustomerRequest = 0;
bool isNotFinished = true;
int UserInputOption = -1;
do {
cout << "Withdrawal options:" << endl;
cout << "1 - cancel transaction" << endl;
cout << "2 - Set the Amount of transaction" << endl;
cout << "choose a withdrawal option (1-2)" << endl;
cin >> UserInputOption;
switch (UserInputOption) {
case 1:
isNotFinished = false;
break;
case 2:
cout << "Enter Amount to WithDraw:" << endl;
cin >> CustomerRequest;
valueToWithdraw = CustomerRequest;
isNotFinished = false;
break;
default:
cout << "Invalid option! Try again." << endl;
break;
}
if (valueToWithdraw != 0) {
if (valueToWithdraw > AccountBalance) {
cout << "Sorry!! Your Account Balance is Only Rupees " << AccountBalance << ". You can't withdraw Rupees " << valueToWithdraw << endl;
}
else {
AccountBalance = AccountBalance - valueToWithdraw;
isNotFinished = false;
}
valueToWithdraw = 0;
}
} while (isNotFinished);
}
void Account::DepositMoney() {
// function of class Account (to deposit money into account)
int UserInputOption = -1;
bool isNotFinished = true;
long depositAmount = 0;
do {
cout << "Cash Deposit Options. Please Enter Your Selection" << endl;
cout << "1 - cancel transaction" << endl;
cout << "2 - Set the Amount of transaction" << endl;
cout << "Choose a deposit option (1-2)" << endl;
cin >> UserInputOption;
switch (UserInputOption) {
case 1:
isNotFinished = false;
break;
case 2:
cout << "Please Enter Amount to Deposit:" << endl;
cin >> depositAmount;
AccountBalance = AccountBalance + depositAmount;
isNotFinished = false;
break;
default:
cout << "Invalid option! Try again." << endl;
break;
}
} while (isNotFinished);
}
int main()
{
Account obj;
if (obj.CheckCustomerDetails()) {
int isNotFinished = true;
do {
switch (obj.MenuDisplay()) {
case 1:
obj.DisplayAccountBalance();
break;
case 2:
obj.WithdrawMoney();
break;
case 3:
obj.DepositMoney();
break;
case 4:
isNotFinished = false;
break;
default:
cout << "Invalid option! Try again." << endl;
break;
}
} while (isNotFinished);
}
return 0;
}