forked from emailam/StudentManagement
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
156 lines (152 loc) · 5.35 KB
/
Main.cpp
File metadata and controls
156 lines (152 loc) · 5.35 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
#include <iostream>
#include <map>
#include <queue>
#include <fstream>
#include <string>
#include "Student.h"
#include "BST.h"
#include "AVL.h"
using namespace std;
template<typename T>
void loadDataFromFile(T &tree){
ifstream file("StudentsData.txt");
string line;
if (file.is_open()){
int cnt = 1 ;
Student student;
getline(file,line);
int n = stoi(line);
while (getline(file, line)){
if(cnt == 1){
student.id = stoi(line);
}
else if(cnt == 2){
student.name = line;
}
else if(cnt == 3){
student.gpa = stod(line);
}
else if(cnt == 4){
student.department = line;
tree.insertStudent(student);
cnt=0;
}
cnt++;
}
file.close();
}
else cout << "File not found !" << endl;
}
int main(){
int choice = 0 ;
while(choice != 5){
cout << "Choose Data Structure: " << endl;
cout << "1- BST" << endl;
cout << "2- AVL" << endl;
cout << "3- Min Heap" << endl;
cout << "4- Max Heap" << endl;
cout << "5- Exit Program" << endl;
cin >> choice;
if(choice == 1){
BST bst;
loadDataFromFile(bst);
while(true){
cout << "Choose one of the following options:" << endl;
cout << "1- Add student" << endl;
cout << "2- Remove student" << endl;
cout << "3- Search student" << endl;
cout << "4- Print All" << endl;
cout << "5- Return to main menu" << endl;
int innerChoice ;
cin >> innerChoice;
if(innerChoice == 1){
Student student;
cout << "Enter student ID : " ;
cin >> student.id ;
cout << "Enter student Name : " ;
cin >> student.name ;
cout << "Enter student GPA : " ;
cin >> student.gpa ;
cout << "Enter student Department : " ;
cin >> student.department ;
bst.insertStudent(student);
cout << "Student added successfully :)" << endl;
}
else if(innerChoice == 2){
cout << "Enter ID of the student you want to delete : " << endl;
int id; cin >> id;
Student student = bst.search(id);
if(student.name != "NULL"){
bst.removeStudent(student);
cout << "Student deleted successfully :)" << endl;
}
}
else if(innerChoice == 3){
cout << "Enter student ID : " ;
int id ; cin >> id ;
bst.search(id);
}
else if(innerChoice == 4){
bst.print();
cout << endl;
}
else if(innerChoice == 5){
break;
}
}
}
else if(choice == 2){
AVL tree ;
loadDataFromFile(tree);
while(true){
cout << "Choose one of the following options:" << endl;
cout << "1- Add student" << endl;
cout << "2- Remove student" << endl;
cout << "3- Search student" << endl;
cout << "4- Print All" << endl;
cout << "5- Return to main menu" << endl;
int innerChoice ;
cin >> innerChoice;
if(innerChoice == 1){
Student student;
cout << "Enter student ID : " ;
cin >> student.id ;
cout << "Enter student Name : " ;
cin >> student.name ;
cout << "Enter student GPA : " ;
cin >> student.gpa ;
cout << "Enter student Department : " ;
cin >> student.department ;
tree.insertStudent(student);
cout << "Student added successfully :)" << endl;
}
else if(innerChoice == 2){
cout << "Enter ID of the student you want to delete : " << endl;
int id; cin >> id;
Student student = tree.search(id);
if(student.name == "NULL") cout << "Student not found !" << endl;
else{
tree.removeStudent(student);
cout << "Student deleted successfully :)" << endl;
}
}
else if(innerChoice == 3){
cout << "Enter student ID : " ;
int id ; cin >> id ;
if(tree.search(id).name == "NULL") cout << "Student not found !" << endl;
}
else if(innerChoice == 4){
tree.inOrderPrint();
cout << endl;
tree.printDepartments();
}
else if(innerChoice == 5){
break;
}
}
}
else if(choice == 5){
exit(0);
}
}
}