-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStudent.cpp
101 lines (77 loc) · 2.08 KB
/
Student.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
#include "Student.h"
int Student::getId() const {
return id;
}
void Student::setId(int id) {
Student::id = id;
}
const string& Student::getSname() const {
return sname;
}
void Student::setSname(const string& sname) {
Student::sname = sname;
}
int Student::getAge() const {
return age;
}
void Student::setAge(int age) {
Student::age = age;
}
const string& Student::getSex() const {
return sex;
}
void Student::setSex(const string& sex) {
Student::sex = sex;
}
const string& Student::getNative() const {
return native;
}
void Student::setNative(const string& native) {
Student::native = native;
}
const string& Student::getDept() const {
return dept;
}
void Student::setDept(const string& dept) {
Student::dept = dept;
}
Student::Student() {
//ƒ¨»œ–¥Œ™0£¨≤»Π˝æ›ø‚÷–ª·◊‘‘ˆ
this->id = 0;
}
bool Student::operator==(const Student& rhs) const {
return id == rhs.id &&
sname == rhs.sname &&
age == rhs.age &&
sex == rhs.sex &&
native == rhs.native &&
dept == rhs.dept;
}
bool Student::operator!=(const Student& rhs) const {
return !(rhs == *this);
}
Student::~Student() {
//cout << "—ß…˙" << this->sname << " has been destroyed" << endl;
}
string Student::toString()
{
char stuString[512];
sprintf(stuString, "%d\t%s\t%s\t%d\t%s\t%s",id,sname.c_str(), sex.c_str(), age, native.c_str(), dept.c_str());
return string(stuString);
}
Student Student::StringToStu(string str)
{
Student s;
stringstream ss(str);
ss >> s.sname >> s.sex >> s.age >> s.native >> s.dept;
return s;
}
ostream& operator<<(ostream& os, const Student& student) {
os << "id: " << student.id << " sname: " << student.sname << " age: " << student.age << " sex: " << student.sex
<< " native: " << student.native << " dept: " << student.dept;
return os;
}
Student::Student(const string& sname, int age, const string& sex, const string& native, const string& dept) : sname(
sname), age(age), sex(sex), native(native), dept(dept) {
id = 0;
}