/
StudentList.cpp
57 lines (49 loc) · 1.29 KB
/
StudentList.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
#include "StudentList.h"
//VERSION 5.3///////////////////////////////////
StudentList::StudentList() {
output_text_file = "default_text_file.txt";
input_text_file = "default_text_file.txt";
}
StudentList::StudentList(string file_name) {
output_text_file = file_name;
input_text_file = file_name;
readFile(file_name);
}
StudentList::~StudentList() {
output_text_file = "default_text_file.txt";
input_text_file = "default_text_file.txt";
}
//Check if the ID is valid
bool StudentList::isValidID(int id) {
student_pos i;
for (i = stu_list.begin(); i != stu_list.end(); ++i) {
int currentID = i->Get_id();
if (currentID == id) return true;
}
return false;
}
//return the position of the ID on array
student_pos StudentList::posOfID(int id) {
student_pos i;
for (i = stu_list.begin(); i != stu_list.end(); ++i) {
int currentID = i->Get_id();
if (currentID == id) return i;
}
}
int StudentList::newID() {
int new_id = stu_list.back().Get_id() + 1;
student_pos i;
for (i = stu_list.begin(); i != stu_list.end(); ++i) {
int currentID = i->Get_id();
if (currentID == new_id) new_id++;
}
return new_id;
}
bool StudentList::userConfirm() {
cout << "Are you sure (Y/N)? ";
//cin.ignore();
char answer;
cin >> answer;
if ((answer == 'y')||(answer == 'Y')) return true;
else return false;
}