Student with set
student.cpp
Go to the documentation of this file.
1 #include "student.h"
2 #include <algorithm> // copy
3 #include <set>
4 #include <string>
5 #include <vector>
6 using namespace std;
7 
9 : _name(), _matr_nr(), _skz()
10 {
11  //ctor
12 }
13 
14 Student::Student(const string& name, const string& matrikel, int studium)
15  : _name(name), _matr_nr(matrikel), _skz{studium}
16 {
17  //ctor
18 
19 }
20 
21 Student::Student(const string & name, const string& matnr, const vector<int>& skz)
22  : _name(name), _matr_nr(matnr),_skz()
23 {
24  //ctor
25  for (auto v:skz)
26  {
27  _skz.insert(v);
28  }
29 }
30 
31 
32 void Student::Add_SKZ(int skz)
33 {
34  _skz.insert(skz);
35 }
36 
37 void Student::Del_SKZ(int skz)
38 {
39  _skz.erase(skz);
40 }
41 
42 vector<int> Student::Get_SKZ() const
43 {
44  vector<int> vv(num_Studies()); // allocate memory
45  copy(_skz.cbegin(),_skz.cend(),vv.begin());
46  return vv;
47 }
48 
49 
50 
51 ostream& operator<<(ostream& s, const Student& rhs)
52 {
53  s << rhs._name << endl;
54  //s << rhs.skz << endl;
55  for (auto v: rhs._skz)
56  {
57  s << v << " ";
58  }
59  s << endl;
60  return s;
61 }
62 
63 istream& operator>>(istream& s, Student& rhs)
64 {
65  s >> rhs._name;
66  int tmp;
67  s >> tmp;
68 // rhs._skz.push_back(tmp);
69  rhs.Add_SKZ(tmp);
70  return s;
71 }
std::vector< int > Get_SKZ() const
Definition: student.cpp:42
void Del_SKZ(const int skz)
Definition: student.cpp:37
int num_Studies() const
Definition: student.h:84
void Add_SKZ(const int skz)
Definition: student.cpp:32
Student()
Definition: student.cpp:8
ostream & operator<<(ostream &s, const Student &rhs)
Definition: student.cpp:51
istream & operator>>(istream &s, Student &rhs)
Definition: student.cpp:63