-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.CPP
207 lines (165 loc) · 5.52 KB
/
ATM.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
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
204
205
206
207
#include<conio.h>
#include<iostream>
#include<string>
using namespace std;
/* Mini Project - ATM
-> Check Balance
-> Cash withdraw
-> User Details
-> Update Mobile No.
*/
class atm // class atm
{
private: // private member varibles
long int account_No;
string name;
int PIN;
double balance;
string mobile_No;
public: // public member functions
// setData function is setting the Data into the private member variables
void setData(long int account_No_a, string name_a, int PIN_a, double balance_a, string mobile_No_a)
{
account_No = account_No_a; // assigning the formal arguments to the private member var's
name = name_a;
PIN = PIN_a;
balance = balance_a;
mobile_No = mobile_No_a;
}
//getAccountNo function is returning the user's account no.
long int getAccountNo()
{
return account_No;
}
//getName function is returning the user's Name
string getName()
{
return name;
}
//getPIN function is returning the user's PIN
int getPIN()
{
return PIN;
}
//getBalance is returning the user's Bank Balance
double getBalance()
{
return balance;
}
//getMobileNo is returning the user's Mobile No.
string getMobileNo()
{
return mobile_No;
}
//setMobile function is Updating the user mobile no
void setMobile(string mob_prev, string mob_new)
{
if (mob_prev == mobile_No) // it will check old Mobile no
{
mobile_No = mob_new; // and Update with new, if old matches
cout << endl << "Sucessfully Updated Mobile no.";
_getch(); //getch is to hold the screen ( untill user press any key )
}
else // Does not update if old mobile no. does not matches
{
cout << endl << "Incorrect !!! Old Mobile no";
_getch(); //getch is to hold the screen ( untill user press any key )
}
}
//cashWithDraw function is used to withdraw money from ATM
void cashWithDraw(int amount_a)
{
if (amount_a > 0 && amount_a < balance) // check entered amount validity
{
balance -= amount_a; // balance = balance - amount_a
cout << endl << "Please Collect Your Cash";
cout << endl << "Available Balance :" << balance;
_getch(); //getch is to hold the screen(untill user press any key )
}
else
{
cout << endl << "Invalid Input or Insufficient Balance";
_getch(); //getch is to hold the screen ( untill user press any key )
}
}
};
/////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
int choice = 0, enterPIN; //enterPIN and enterAccountNo. ---> user authentication
long int enterAccountNo;
system("cls");
// created User ( object )
atm user1;
// Set User Details ( into object ) ( Setting Default Data )
user1.setData(1234567, "Tim", 1111, 45000.90, "9087654321");
do
{
system("cls");
cout << endl << "****Welcome to ATM*****" << endl;
cout << endl << "Enter Your Account No "; // asking user to enter account no
cin >> enterAccountNo;
cout << endl << "Enter PIN "; // asking user to enter PIN
cin >> enterPIN;
// check whether enter values matches with user details
if ((enterAccountNo == user1.getAccountNo()) && (enterPIN == user1.getPIN()))
{
do
{
int amount = 0;
string oldMobileNo, newMobileNo;
system("cls");
// user Interface
cout << endl << "**** Welcome to ATM *****" << endl;
cout << endl << "Select Options ";
cout << endl << "1. Check Balance";
cout << endl << "2. Cash withdraw";
cout << endl << "3. Show User Details";
cout << endl << "4. Update Mobile no.";
cout << endl << "5. Exit" << endl;
cin >> choice; // taking user choice
switch (choice) // switch condition
{
case 1: // if user presses 1
cout << endl << "Your Bank balance is :" << user1.getBalance();
// getBalance is ... printing the users bank balance
_getch();
break;
case 2: // if user presses 2
cout << endl << "Enter the amount :";
cin >> amount;
user1.cashWithDraw(amount); // calling cashWithdraw function
// passing the withdraw amount
break;
case 3: // if user presses 3
cout << endl << "*** User Details are :- ";
cout << endl << "-> Account no" << user1.getAccountNo();
cout << endl << "-> Name " << user1.getName();
cout << endl << "-> Balance " << user1.getBalance();
cout << endl << "-> Mobile No." << user1.getMobileNo();
// getting and printing user details
_getch();
break;
case 4: // if user presses 4
cout << endl << "Enter Old Mobile No. ";
cin >> oldMobileNo; // take old mobile no
cout << endl << "Enter New Mobile No. ";
cin >> newMobileNo; // take new mobile no
user1.setMobile(oldMobileNo, newMobileNo); // now set new mobile no
break;
// if user presses 5
case 5:
exit(0); // exit application
default: // handle invalid user inputs
cout << endl << "Enter Valid Data !!!";
}
} while (1); // MENU // condition will always TRUE and loop is capable of running infinite times
}
else
{
cout << endl << "User Details are Invalid !!! ";
_getch();
}
} while (1); //LOGIN // condition will always TRUE and loop is capable of running infinite times
return 0;
}