-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1.cpp
More file actions
295 lines (266 loc) · 6.78 KB
/
project1.cpp
File metadata and controls
295 lines (266 loc) · 6.78 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fstream>
#define FILE "register.txt"
using namespace std;
class Bank {
// Private variables used inside class
private:
string name;
int accnumber;
char type[10];
int amount = 0;
int tot = 0;
int pin;
// Public variables
public:
// Function to set the person's data
void setvalue()
{
char ch[2];
cout << "Enter name\n";
cin.ignore();
// To use space in string
getline(cin, name);
cout << "Enter Account number\n";
cin >> accnumber;
cout << "Enter Account type: Saving or Current?\n";
cin >> type;
cout << "Generate your pin number\n";
cin >> pin;
cout << "Deposit Initial Balance (>=1000 for Saving and <=3000 for Current)\n";
cin >> tot;
if(tot<1000)
{
cout << "Error!! Please follow above rules for your account type\n";
cout << "Go back to start\n";
}
else if(tot>3000)
{
cout << "Error!! Please follow above rules for your account type\n";
cout << "Go back to start\n";
}
else
{
cout << "Welcome!! Your account was Created\n";
}
cout<<"\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function to display the required data
void showdata()
{
char ch[2];
cout << "Name:" << name << endl;
cout << "Account No:" << accnumber << endl;
cout << "Account type:" << type << endl;
cout << "Balance:" << tot<< endl;
cout<<"\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function to deposit the amount in ATM
void deposit()
{
int acc_no;
int Pin;
char ch[2];
cout<< "Enter the Account Number\n";
cin>> acc_no;
cout<< "Enter the Pin Number\n";
cin>>Pin;
if(acc_no==accnumber && Pin==pin)
{
cout << "\nEnter amount to be Deposited\n";
cin >> amount;
tot+= amount;
amount= 0;
}
else
cout << "\nInvalid Credentials!\n";
cout<<"\n\n\n\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function to show the balance amount
void showbal()
{
char ch[2];
cout << "\nTotal balance is: " << tot;
cout<<"\n\n\n\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function to change pin number
void pinchang()
{
int OpinNo, CpinNo;
char ch[2];
cout <<"Enter your old pin number\n";
cin >> OpinNo;
if(OpinNo==pin)
{
cout <<"Enter new pin number\n";
cin >> CpinNo;
pin= CpinNo;
cout <<"Congrats!! Your Pin number is Updated...\n";
}
else
{
cout << "\nInvalid Pin No!\n";
}
cout<<"\n\n\n\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function to withdraw the amount in ATM
void withdrawl()
{
int pin_no;
int a;
char chr;
char ch[2];
cout<<"Firstly Do you want Receipt?\n" << "Enter Y for Yes: Enter N for No\n";
cin>>ch;
if (chr=='Y'|| chr=='y')
{
cout<< "Here your details\n";
}
else
{
}
cout << "Enter your Pin number\n";
cin>> pin_no;
if(pin_no==pin)
{
cout << "Enter amount to withdraw\n";
cin >> a;
if(a<=tot)
{
cout << "Withdrawal successful!\n";
tot -= a;
cout << "Available Balance is\n" << tot;
}
else
cout << "Account does not have enough balance!\n";
}
cout<<"\n\n\n\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// Function using File handing to read, write & store account details
void showReg()
{
system("cls");
Bank obj;
int i=0;
ifstream in;
in.open("register.txt", ios::in);
in.read((char *)&obj, sizeof(obj));
while(!in.eof())
{
cout<<"Entry no. "<<++i<<": \n";
obj.showdata();
cout<<endl<<endl;
in.read((char *)&obj, sizeof(obj));
}
in.close();
cout<<"\n\n\nTotal number of entries so far: "<<i;
char ch[2];
cout<<"\n\n\n\nPress Enter to continue...";
cin.ignore();
cin.getline(ch, 2, '\n');
}
// atm a;
// ifstream file1;
// // Open file in read mode
// file1.open("aaa.txt", ios::in);
// if (!file1) {
// cout << "Error in opening file..";
// return 0;
// }
// // Read data from file
// file1.read((char*)&a, sizeof(a));
// while (!file1.eof()) {
// // Display data on monitor
// a.showData();
// file1.read((char*)&a, sizeof(a));
// }
// // Close the file
// file1.close();
// return 0;
// }
// Function to cancel the process in ATM
void canl()
{
cout<< "\nTHANK YOU FOR VISTING\n";
}
};
// Driver Code
int main()
{
// Give color in program
system("color A0");
// Object of class
Bank b;
int choice;
// Infinite while loop to choose
// options everytime
system("cls");
while (1) {
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~"
<< "~~~~~~~~~~~~~"
<< "~ WELCOME TO UCO BANK ~~~~~~~~~~~~~~~~~~"
<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
<< "~~~~~~~~~\n\n";
// It gives current date & time
time_t timetoday;
time(&timetoday);
cout << "TODAY THE DATE and TIME ;\n" <<asctime(localtime(&timetoday));
cout << "\n";
cout << "\t1. Create an Account.\n";
cout << "\t2. Deposit Money.\n";
cout << "\t3. Change Pin Number.\n";
cout << "\t4. Show Account Preview.\n";
cout << "\t5. Withdraw Money.\n";
cout << "\t6. Show Register file.\n";
cout << "\t7. Total balance.\n";
cout << "\t8. Exit ATM.\n";
cout << "\nSelect the Option (1-8).\n";
cin >>choice;
system("cls");
// Choices to select from
switch (choice)
{
case 1:
b.setvalue();
break;
case 2:
b.deposit();
break;
case 3:
b.pinchang();
break;
case 4:
b.showdata();
break;
case 5:
b.withdrawl ();
break;
case 6:
b.showReg();
break;
case 7:
b.showbal ();
break;
case 8:
b.canl();
exit(1);
default:
cout << "\nInvalid choice\n";
}
}
}