-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_handler.cpp
More file actions
102 lines (84 loc) · 2.53 KB
/
data_handler.cpp
File metadata and controls
102 lines (84 loc) · 2.53 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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#ifdef _WIN32
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
using namespace std;
// Function to clear the screen
void clearScreen() {
system(CLEAR);
}
// Function to display the file manager menu
void Display_FileManager_Menu() {
cout << "\n========= File Manager =========\n";
cout << "01. VIEW ACCOUNTS (without PINs)\n";
cout << "02. VIEW PINs (mapped to account numbers)\n";
cout << "03. EXIT\n";
cout << "\nSELECT OPTION: ";
}
// Function to view account details (excluding PINs)
void viewAccounts() {
clearScreen();
ifstream inFile("accounts.dat");
if (!inFile) {
cout << "\n ERROR: Unable to open accounts.dat file!\n";
return;
}
cout << "\n========= ACCOUNT DETAILS =========\n";
string accountNumber, pin, name;
double balance;
bool found = false;
while (inFile >> accountNumber >> pin >> ws) {
getline(inFile, name, ' ');
inFile >> balance;
cout << "\n Account Number: " << accountNumber;
cout << "\n Holder: " << name;
cout << "\n Balance: Rs. " << fixed << setprecision(2) << balance;
cout << "\n-----------------------------------\n";
found = true;
}
inFile.close();
if (!found) cout << "\n No accounts found in the database!\n";
}
// Function to view PINs mapped to account numbers
void viewPins() {
clearScreen();
ifstream inFile("accounts.dat");
if (!inFile) {
cout << "\n ERROR: Unable to open accounts.dat file!\n";
return;
}
cout << "\n========= PIN DETAILS =========\n";
string accountNumber, pin, name;
double balance;
bool found = false;
while (inFile >> accountNumber >> pin >> ws) {
getline(inFile, name, ' ');
inFile >> balance;
cout << " Account: " << accountNumber << " | PIN: " << pin << "\n";
found = true;
}
inFile.close();
if (!found) cout << "\n No PINs found in the database!\n";
}
int main() {
char choice;
do {
clearScreen();
Display_FileManager_Menu();
cin >> choice;
switch (choice) {
case '1': viewAccounts(); break;
case '2': viewPins(); break;
case '3': cout << "\n Exiting File Manager. Thank you!\n"; break;
default: cout << "\n Invalid Option! Try Again.\n";
}
cin.ignore();
cin.get(); // Pause before clearing the screen again
} while (choice != '3');
return 0;
}