-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.cpp
138 lines (117 loc) · 3.1 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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class ATM{
private:
string pin;
double balance;
const string filename = "atm_data.txt";
public:
ATM() {
ifstream file(filename);
if(file){
getline(file,pin);
file >> balance;
file.close();
}
else{
pin ="9090";
balance = 1000.0;
saveToFile();
}
}
void saveToFile(){
ofstream file(filename);
file << pin << endl;
file << balance << endl;
file.close();
}
bool authenticate(string enteredpin){
return (enteredpin == pin);
}
void checkbalance(){
cout << "Your balance is: " << balance << endl;
}
void deposit(){
double depositAmount;
cout<<"enter the amount to deposit: ";
cin >> depositAmount;
if(depositAmount >0) {
balance += depositAmount;
cout<< "you have deopsited : ₹ " << depositAmount <<endl;
saveToFile();
cout<< "your updated total balance is: ₹ " << balance <<endl;
}
else{
cout<<"invalid deopisit amount"<<endl;
}
}
void withdraw(){
double withdrawAmount;
cout<<"enter the amount to withdraw: ";
cin >> withdrawAmount;
if(withdrawAmount >0 && withdrawAmount <= balance) {
balance -= withdrawAmount;
cout<< "you have withdrawn : ₹" << withdrawAmount <<endl;
saveToFile();
cout<< "your updated total balance is: ₹" << balance <<endl;
}
else if(withdrawAmount > balance){
cout<<"insufficient amount"<<endl;
}
else{
cout<<"invalid withdraw amount"<<endl;
}
}
void changepin(){
string newpin;
cout<<"enter new pin" <<endl;
cin>>newpin;
pin = newpin;
cout<< "your pine has been changed successfully"<<endl;
saveToFile();
}
};
int main(){
ATM atm;
string enteredpin;
int choice;
cout<<"welcone to the ATM"<<endl;
cout<<"enter your atm pin;" <<endl;
cin >> enteredpin;
if(!atm.authenticate(enteredpin)){
cout<<"invalid pin,enter correct pin"<<endl;
return 0;
}
do{
cout << " ATM MENU" << endl;
cout << "1. check balance "<< endl;
cout << "2. deposit Money"<<endl;
cout << "3. withraw Money" << endl;
cout << "4. change PIN"<< endl;
cout << "5. exit"<< endl;
cout << " ENTER YOUR CHOICE"<< endl;
cin >> (choice);
switch(choice){
case 1:
atm.checkbalance();
break;
case 2:
atm.deposit();
break;
case 3:
atm.withdraw();
break;
case 4:
atm.changepin();
break;
case 5:
cout<<" THANK YOU FOR USING ATM , HAVE A NICE DAY" <<endl;
break;
default:
cout<< " INVALID CHOICE, PLEASE TRY AGAIN" << endl;
}
}while(choice != 5);
return 0;
}