-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudentExample.cc
More file actions
92 lines (76 loc) · 1.76 KB
/
studentExample.cc
File metadata and controls
92 lines (76 loc) · 1.76 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <set>
#include <queue>
#include <string>
#include <iostream>
class Student
{
private:
int id;
std::string name;
public:
// Constructors
Student(){}; // default constructor
Student(int id, std::string name) : id(id), name(name){};
Student(const Student &s) : id(s.id), name(s.name){}; // Copy-constructor
// Destructor
~Student(){};
// Methods
int getId() const
{
return id;
}
std::string getName() const
{
return name;
}
// Comparison operator overload for Set
bool operator<(const Student &other) const
{
return id < other.id;
}
};
class ClassRoom
{
private:
std::set<Student> students;
public:
// Constructors
ClassRoom(){}; // default constructor
ClassRoom(const std::vector<Student> &s)
{
for (auto temp : s)
{
auto i = students.insert(temp);
if (!i.second)
break;
}
};
ClassRoom(const ClassRoom &c) : students(c.students){}; // copy-constructor
// Destructor
~ClassRoom(){};
// Methods
std::set<Student>::const_iterator addStudent(const Student &s)
{
auto i = students.insert(s);
if (!i.second)
{
return students.end();
}
return i.first;
}
};
// Print operator overload Student
std::ostream &operator<<(std::ostream &output, const Student &s)
{
output << "(" << s.getId() << ", " << s.getName() << ")";
return output;
}
int main(int argc, char const *argv[])
{
std::string arr[5] = {"Frank", "Billy", "Alice", "Bob", "Mango"};
ClassRoom itClass;
Student bob(5, "Bob");
auto bobItr = itClass.addStudent(bob);
std::cout << "Student info: " << *bobItr << std::endl;
return 0;
}