/
StudentFileController.cpp
82 lines (70 loc) · 2.09 KB
/
StudentFileController.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
#include "StudentList.h"
#include <string.h>
void StudentList::subString(string oString) {
string temp, t_name, t_Dob, t_add, t_pro, t_class_name;
int t_id, t_enTr;
//lay id
int mark = oString.find(":");
t_id = atoi(oString.substr(0,mark).c_str());
//lay name
temp = oString.substr(mark+1);
mark = temp.find(":");
t_name = temp.substr(0,mark);
//lay DOB
temp = temp.substr(mark+1);
mark = temp.find(":");
t_Dob = temp.substr(0,mark);
//Lay Address
temp = temp.substr(mark+1);
mark = temp.find(":");
t_add = temp.substr(0,mark);
//Lay Entry Year
temp = temp.substr(mark+1);
mark = temp.find(":");
t_enTr = atoi(temp.substr(0,mark).c_str());
//Lay class
temp = temp.substr(mark+1);
mark = temp.find(":");
t_class_name = temp.substr(0,mark);
//Lay Programe
temp = temp.substr(mark+1);
mark = temp.find(":");
t_pro = temp.substr(0,mark);
Student sv(t_id,t_name,t_Dob,t_add,t_enTr,t_class_name,t_pro);
stu_list.push_back(sv);
}
//readFile, ghi vao mang l[] voi size la so sv truoc khi them
void StudentList::readFile(string _file){
ifstream fin;
fin.open(_file.c_str());
if(!fin.is_open())
{
cout<<"Khong the mo file.\n";
exit(1);
}else{
string s = "";
while (getline(fin, s)){
subString(s);
}
fin.close();
}
}
//writeFile
void StudentList::writeFile(string _file){
ofstream fout;
fout.open(_file.c_str());
student_pos i;
for (i = stu_list.begin(); i != stu_list.end(); ++i){
fout << i->Get_id() << ":" << i->Get_name() << ":" << i->Get_dOB() << ":" << i->Get_address()
<< ":" << i->Get_enter_year() << ":" <<i->Get_class_name()<< ":" <<i->Get_major() <<endl;
}
fout.close();
}
//print the loaded list of students
void StudentList::printStuList() {
student_pos i;
for (i = stu_list.begin(); i != stu_list.end(); ++i){
i->Print();
cout << endl;
}
}