-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
141 lines (115 loc) · 2.89 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
139
140
141
#include "Main.h"
#include "Student.h"
#include <list>
#include "Windows.h"
using namespace std;
void menuEntry()
{
cout << "* * * * * * * * * * * * * * * * * * * * *" << endl;
cout << "* *" << endl;
cout << "* MENU *" << endl;
cout << "* *" << endl;
cout << "* * * * * * * * * * * * * * * * * * * * *" << endl;
cout << endl;
cout << "1. Add new student." << endl;
cout << "2. Show student list." << endl;
cout << "3. Delete a student by ID" << endl;
cout << "4. Find a student by ID" << endl;
cout << "5. Quit from Menu" << endl;
}
void addNewStudent(list<Student> *list)
{
int id, grade;
string name, surName;
cout << "Please enter student Id: " << endl;
cin >> id;
cout << "Please enter student name: " << endl;
cin >> name;
cout << "Please enter student surName: " << endl;
cin >> surName;
cout << "Please enter student Grade: " << endl;
cin >> grade;
Student student(id, name, surName, grade);
list->push_back(student);
system("cls");
cout << "Student added succesfully!" << endl << endl << endl;
}
void showList(list<Student> *lst)
{
cout << endl << "-----------------Student List------------\n";
list<Student>::iterator itr;
for (itr = lst->begin(); itr != lst->end(); itr++)
{
itr->getInformation();
}
cout << endl;
cout << endl;
}
void deleteStudent(list<Student>* lst)
{
list<Student>::iterator itr;
int id;
cout << "Please enter student Id to delete: " << endl;
cin >> id;
for (itr = lst->begin(); itr != lst->end(); itr++)
{
if (itr->getId() == id)
{
break;
}
}
if (itr == lst->end())
{
cout << "Student with id " << id << " is not in the list!" << endl;
cout << "Id " << id << " student can not be deleted !" << endl;
}
else
{
cout << "Student is found!" << endl;
lst->erase(itr);
cout << "Id " << id << " student is deleted from the list!" << endl;
}
}
void findStudent(list<Student>* lst)
{
list<Student>::iterator itr;
int id;
cout << "Please enter student Id to find: " << endl;
cin >> id;
for (itr = lst->begin(); itr != lst->end(); itr++)
{
if (itr->getId() == id)
{
break;
}
}
if (itr == lst->end())
{
cout << "Student with id " << id << " is not in the list!" << endl;
}
else
{
cout << endl << "Student is found!" << endl;
itr->getInformation();
}
}
int main()
{
list<Student> *studentList = new list<Student>();
int selection = 0;
cout << endl;
do
{
menuEntry();
cout << "Waiting for your choice: " << endl;
cin >> selection;
if (selection == 1) { addNewStudent(studentList); }
else if (selection == 2){ showList(studentList); }
else if (selection == 3){ deleteStudent(studentList); }
else if (selection == 4){ findStudent(studentList); }
else if (selection == 5){ break; }
else { cout << "Wrong choice. Try again please...."; }
} while (selection != 5);
cout << endl;
return 0;
}