-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
138 lines (125 loc) · 3.09 KB
/
main.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 "main.h"
/**
* displayMenu - main menu of the program
* @head: head of students Linked list
*
* Return: Nothing
*/
void displayMenu(StudentNode* head)
{
bool exitMenu = false;
while (!exitMenu)
{
std::cout << "+--------------------------------+\n";
std::cout << "| Menu |\n";
std::cout << "+--------------------------------+\n";
std::cout << "| 1. Add Student |\n";
std::cout << "| 2. Delete Student |\n";
std::cout << "| 3. List all added students |\n";
std::cout << "| 4. Add Subjects for a student |\n";
std::cout << "| 5. Display Subjects with Grades|\n";
std::cout << "| 6. Save data |\n";
std::cout << "| 7. Load Data |\n";
std::cout << "| 8. Exit |\n";
std::cout << "+--------------------------------+\n";
std::cout << "Enter your choice: ";
int choice;
std::cin >> choice;
switch (choice)
{
case 1:
{
std::string student1;
inputStudentDetails(student1);
insertStudent(head, student1);
clearTerminal();
std::cout << "Stdudent added successfuly!\n";
break;
}
case 2:
{
std::string studentName;
std::cout << "Enter the name of the student to delete: ";
std::cin.ignore();
std::getline(std::cin, studentName);
head = delStud(head, studentName);
break;
}
case 3:
{
listAllStudents(head);
std::cin.ignore();
clearTerminal();
break;
}
case 4:
{
std::string studentName;
std::cout << "Enter student name: ";
std::cin.ignore(); // Ignore any previous newline character
std::getline(std::cin, studentName);
StudentNode* currentStudent = findStudent(head, studentName);
if (currentStudent != nullptr)
{
addSubjectInfo(currentStudent);
}
else
{
clearTerminal();
std::cout << "Student not found.\n";
}
break;
}
case 5:
{
std::string studentName;
std::cout << "Enter student name: ";
std::cin.ignore(); // Ignore any previous newline character
std::getline(std::cin, studentName);
StudentNode* current = findStudent(head, studentName);
if (current != nullptr)
{
displaySubjects(current);
}
else
{
clearTerminal();
std::cout << "Student not found.\n";
}
break;
}
case 6:
{
std::string filename;
std::cout << "Enter filename to save data: ";
std::cin >> filename;
saveDataToFile(filename, head);
break;
}
case 7:
loadData(head);
break;
case 8:
cleanMemory(head);
exitMenu = true;
break;
default:
std::cout << "Invalid choice. Please try again.\n";
std::cin.clear(); // Clear the error state of the input stream
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Discard remaining input
break;
}
}
}
/**
* main - main function where it all starts
*
* Return: 0(success)
*/
int main(void)
{
StudentNode* head = nullptr;
// Display menu
displayMenu(head);
return (0);
}