First Class
student.h
Go to the documentation of this file.
1 #pragma once
2 #include <algorithm> // find
3 #include <iostream> // ostream
4 #include <string>
5 #include <vector>
6 //using namespace std;
7 
10 class Student
11 {
12 public:
15  Student();
16 
24  Student(const std::string& fname, const std::string& matrikel, const int studium);
25 
33  Student(const std::string& fname, const std::string& matrikel, const std::vector<int>& studium); // new
34 
35  // automatic generation of copy constructor and assignment operator by the compiler
36  // in C++11: the Assignment operator (and any other method) can be explicitely deleted via:
37  // Student& operator=(const Student& other) = delete;
38  Student(const Student &orig) = default;
39 
40  Student& operator=(const Student &rhs) = default;
41 
42 
44  // virtual
45  ~Student() {}
46 
47 
51  std::string Getname() const
52  {
53  return _name;
54  }
59  void Setname(const std::string& val);
67  std::string Getmatr_nr() const
68  {
69  return _matr_nr;
70  }
71 
77  void Add_SKZ(const int skz_in);
78 
83  void Del_SKZ(const int skz_in);
84 
88  const std::vector<int>& Get_SKZ() const
89  {
90  return _skz;
91  }
92 
96  int Num_SKZ() const
97  {
98  return static_cast<int>(_skz.size());
99  }
100 
105  friend std::ostream& operator<<(std::ostream& s, const Student& rhs);
106 
112  friend std::istream& operator>>(std::istream& s, Student& rhs);
113 
120  bool operator<(const Student& rhs) const
121  {
122  return _name < rhs._name;
123  }
124 
131  bool Enrolled4Study(const int cSKZ) const
132  {
133  return _skz.end() != find(_skz.begin(), _skz.end(), cSKZ); // find uses operator==(int,int)
134  }
135 
136 protected:
137 
138 private:
139  std::string _name;
140  std::string _matr_nr;
141  std::vector<int> _skz;
142 };
bool Enrolled4Study(const int cSKZ) const
Checks whether a student is enrolled in study cSKZ.
Definition: student.h:131
void Add_SKZ(const int skz_in)
Definition: student.cpp:29
int Num_SKZ() const
Definition: student.h:96
Student & operator=(const Student &rhs)=default
~Student()
Definition: student.h:45
const std::vector< int > & Get_SKZ() const
Definition: student.h:88
friend std::ostream & operator<<(std::ostream &s, const Student &rhs)
Student(const Student &orig)=default
bool operator<(const Student &rhs) const
Compares two students wrt. the lexicographical ordering of names.
Definition: student.h:120
Student(const std::string &fname, const std::string &matrikel, const std::vector< int > &studium)
Parameter constructor.
std::string Getname() const
Definition: student.h:51
Student(const std::string &fname, const std::string &matrikel, const int studium)
Parameter constructor.
void Del_SKZ(const int skz_in)
Definition: student.cpp:36
void Setname(const std::string &val)
Definition: student.cpp:27
std::string Getmatr_nr() const
Definition: student.h:67
Student()
Default constructor.
Definition: student.cpp:7
friend std::istream & operator>>(std::istream &s, Student &rhs)