First Class
Loading...
Searching...
No Matches
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
9class Student
10{
11public:
15 : _name(), _matr_nr(), _skz() {}
16
24 Student(const std::string& fname, const std::string& matrikel, const int studium)
25 : Student(fname,matrikel,std::vector<int>{studium}) // constructor forwarding
26 {}
34 Student(const std::string& fname, const std::string& matrikel, const std::vector<int>& studium) // new
35 : _name(fname), _matr_nr(matrikel), _skz(studium)
36 {}
37
38 // automatic generation of copy constructor and assignment operator by the compiler
39 // in C++11: the Assignment operator (and any other method) can be explicitely deleted via:
40 // Student& operator=(const Student& other) = delete;
41 Student(const Student &orig) = default;
42 Student& operator=(const Student &rhs) = default;
43 ~Student() = default;
44
48 std::string Getname() const
49 { return _name; }
50
54 void Setname(const std::string& val)
55 { _name = val; }
56
60 std::string Getmatr_nr() const
61 {
62 return _matr_nr;
63 }
64
70 void Add_SKZ(const int skz_in);
71
76 void Del_SKZ(const int skz_in);
77
81 const std::vector<int>& Get_SKZ() const
82 {
83 return _skz;
84 }
85
89 int Num_SKZ() const
90 {
91 return static_cast<int>(_skz.size());
92 }
93
98 friend std::ostream& operator<<(std::ostream& s, const Student& rhs);
99
105 friend std::istream& operator>>(std::istream& s, Student& rhs);
106
113 bool operator<(const Student& rhs) const
114 {
115 return _name < rhs._name;
116 }
117
124 bool Enrolled4Study(const int cSKZ) const
125 {
126 return _skz.end() != find(_skz.begin(), _skz.end(), cSKZ); // find uses operator==(int,int)
127 }
128
129protected:
130
131private:
132 std::string _name;
133 std::string _matr_nr;
134 std::vector<int> _skz;
135};
bool Enrolled4Study(const int cSKZ) const
Checks whether a student is enrolled in study cSKZ.
Definition student.h:124
const std::vector< int > & Get_SKZ() const
Definition student.h:81
void Add_SKZ(const int skz_in)
Definition student.cpp:8
int Num_SKZ() const
Definition student.h:89
friend std::ostream & operator<<(std::ostream &s, const Student &rhs)
Student & operator=(const Student &rhs)=default
Student(const Student &orig)=default
~Student()=default
bool operator<(const Student &rhs) const
Compares two students wrt. the lexicographical ordering of names.
Definition student.h:113
Student(const std::string &fname, const std::string &matrikel, const std::vector< int > &studium)
Parameter constructor.
Definition student.h:34
std::string Getname() const
Definition student.h:48
Student(const std::string &fname, const std::string &matrikel, const int studium)
Parameter constructor.
Definition student.h:24
friend std::istream & operator>>(std::istream &s, Student &rhs)
void Del_SKZ(const int skz_in)
Definition student.cpp:15
void Setname(const std::string &val)
Definition student.h:54
std::string Getmatr_nr() const
Definition student.h:60
Student()
Default constructor.
Definition student.h:14