forked from Xiaoyuan-Liu/Student-Information-Manage-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudentdatabase.cpp
More file actions
72 lines (61 loc) · 1.49 KB
/
studentdatabase.cpp
File metadata and controls
72 lines (61 loc) · 1.49 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
#include<algorithm>
using namespace std;
#include"studentdatabase.h"
const student studentDatabase::getStudent(int index){
return stu[index];
}
const int studentDatabase::getSize(){
return stu.size();
}
void studentDatabase::addStudent(){
student *tmp = new student();
stu.push_back(*tmp);
delete tmp;
}
bool studentDatabase::addStudent(student stu){
if(findStudent(stu)==-1)return false;
this->stu.push_back(stu);
sortByGPA();
}
//bool studentDatabase::addStudent(student stu);
bool studentDatabase::deleteStudent(int index){
stu.erase(stu.begin()+index);
}
bool studentDatabase::deleteStudent(student stu){
int index = findStudent(stu);
if(index==-1)return false;
else{
this->stu.erase(this->stu.begin() + index);
return true;
}
}
const int studentDatabase::findStudent(student stu){
for(int i = 0;i < this->stu.size();i++){
if(this->stu[i]==stu)
return i;
}
return -1;
}
const int studentDatabase::findStudent(string name){
for(int i = 0;i<this->stu.size();i++){
if(this->stu[i]==name)
return i;
}
return -1;
}
const int studentDatabase::findStudent(int id){
for(int i = 0;i<this->stu.size();i++){
if(this->stu[i]==id)
return i;
}
return -1;
}
bool studentDatabase::clear(){
stu.clear();
}
bool sortCmp(student s1, student s2){
return s1.getGPA()<s2.getGPA();
}
void studentDatabase::sortByGPA(){
sort(stu.begin(),stu.end(),sortCmp);
}