-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
129 lines (116 loc) · 4.84 KB
/
Source.cpp
File metadata and controls
129 lines (116 loc) · 4.84 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
#include <iostream>
#include <string>
#include <limits>
#ifdef _WIN32
#define NOMINMAX // Prevent Windows.h from defining min and max macros
#include <windows.h>
#endif
#include "Student.h"
#include "Directory.h"
#include "UIUtils.h"
using namespace std;
static void clearScreen() {
#ifdef _WIN32
system("CLS");
#else
cout << "\033[2J\033[1;1H";
#endif
}
static void pressEnterToContinue() {
cout << UI::YELLOW << "\n >>> Press Enter to continue... " << UI::RESET;
// std::max is now safe because of NOMINMAX
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
static void displayMenu() {
UI::printHeader();
cout << UI::CYAN << " ┌───────────────────────────────────────────┐" << endl;
cout << " │ " << UI::BOLD << "MAIN MENU" << UI::RESET << UI::CYAN << " │" << endl;
cout << " ├───────────────────────────────────────────┤" << endl;
cout << " │ " << UI::YELLOW << "[1]" << UI::RESET << " Insert a New Student │" << endl;
cout << " │ " << UI::YELLOW << "[2]" << UI::RESET << " Update Existing Record │" << endl;
cout << " │ " << UI::YELLOW << "[3]" << UI::RESET << " Delete a Record │" << endl;
cout << " │ " << UI::YELLOW << "[4]" << UI::RESET << " Search Registry (Name/ID) │" << endl;
cout << " │ " << UI::YELLOW << "[5]" << UI::RESET << " List All Students │" << endl;
cout << " │ " << UI::YELLOW << "[6]" << UI::RESET << " Sort Registry by Name │" << endl;
cout << " │ " << UI::YELLOW << "[7]" << UI::RESET << " Sort Registry by ID │" << endl;
cout << " │ " << UI::RED << "[8]" << UI::RESET << " Save and Exit │" << endl;
cout << UI::CYAN << " └───────────────────────────────────────────┘" << UI::RESET << endl;
cout << UI::BOLD << " Select Choice [1-8]: " << UI::RESET;
}
int main() {
// FIX: Set Windows Console to UTF-8 to support Boxes and ASCII Art
#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
#endif
Directory directory;
const string filename = "registry.txt";
clearScreen();
UI::showLoading(" Initializing Registry Engine");
directory.loadFromFile(filename);
int choice = 0;
while (true) {
clearScreen();
displayMenu();
if (!(cin >> choice)) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
continue;
}
cin.ignore();
if (choice == 8) {
UI::showLoading(" Encrypting and Saving Data");
directory.saveToFile(filename);
cout << UI::GREEN << "\n Registry Safe. Have a great day!" << UI::RESET << endl;
break;
}
switch (choice) {
case 1: {
string n, i, a, p;
cout << UI::CYAN << "\n --- New Record Entry ---\n" << UI::RESET;
cout << " Enter Name: "; getline(cin, n);
cout << " Enter ID: "; getline(cin, i);
cout << " Enter Addr: "; getline(cin, a);
cout << " Enter Phon: "; getline(cin, p);
directory.insertStudent(Student(n, i, a, p));
break;
}
case 2: {
string id;
cout << UI::YELLOW << "\n Enter ID to update: " << UI::RESET; getline(cin, id);
directory.updateStudent(id);
break;
}
case 3: {
string id;
cout << UI::RED << "\n Enter ID to DELETE: " << UI::RESET; getline(cin, id);
directory.deleteStudent(id);
break;
}
case 4: {
string query;
cout << UI::CYAN << "\n Search System (Sub-string scan): " << UI::RESET; getline(cin, query);
directory.searchStudent(query);
break;
}
case 5: {
directory.listDirectory();
break;
}
case 6: {
UI::showLoading(" Optimizing Alphabetical Order");
directory.sortByName();
break;
}
case 7: {
UI::showLoading(" Indexing by Numerical ID");
directory.sortByID();
break;
}
default:
UI::printError("Invalid choice detected!");
}
pressEnterToContinue();
}
return 0;
}