-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_type.hpp
More file actions
63 lines (50 loc) · 1.34 KB
/
custom_type.hpp
File metadata and controls
63 lines (50 loc) · 1.34 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
#ifndef __CUSTOM_TYPE__
#define __CUSTOM_TYPE__
#include <string>
#include <ostream>
class Student {
private:
std::string name;
unsigned int age;
unsigned int id;
public:
Student() : name(""), age(0), id(0) {
}
Student(std::string name, unsigned int age, unsigned int id) : name(name), age(age), id(id) {
}
void setStudentInfo(std::string name, unsigned int age, unsigned int id) {
this->name = name;
this->age = age;
this->id = id;
}
Student& operator=(const Student& other) {
name = other.name;
age = other.age;
id = other.id;
return *this;
}
bool operator==(const Student& other) const {
if (name != other.name) return false;
else if (age != other.age) return false;
else if (id != other.id) return false;
else return true;
}
bool operator!=(const Student& other) const {
if (name == other.name) return false;
else if (age == other.age) return false;
else if (id == other.id) return false;
else return true;
}
bool operator<(const Student& other) const {
return id < other.id;
}
bool operator>(const Student& other) const {
return id > other.id;
}
friend std::ostream& operator<< (std::ostream& out, Student& student);
};
std::ostream& operator<< (std::ostream& out, Student& student) {
out << student.id << " " << student.name << " (" << student.age << ")";
return out;
}
#endif // !__CUSTOM_TYPE__