98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#include "iostream"
|
|
#include "string"
|
|
#include "vector"
|
|
#include <numeric>
|
|
|
|
class University;
|
|
class UniMember {
|
|
public:
|
|
University* uni;
|
|
std::string name;
|
|
int id;
|
|
|
|
UniMember(University* university, std::string name, int id) {
|
|
this->uni = university;
|
|
this->name = name;
|
|
this->id = id;
|
|
}
|
|
};
|
|
|
|
class UniWorker: public UniMember {
|
|
public:
|
|
UniWorker(University* university, std::string name, int id)
|
|
: UniMember(university, name, id) {}
|
|
|
|
};
|
|
|
|
class UniStudent: public UniMember {
|
|
public:
|
|
UniStudent(University* university, std::string name, int id)
|
|
: UniMember(university, name, id) {}
|
|
|
|
void evaluate_exam(double grade){
|
|
grades.push_back(grade);
|
|
}
|
|
|
|
double calc_avg(){
|
|
if(grades.empty()) return 0;
|
|
auto const count = static_cast<double>(grades.size());
|
|
return std::reduce(grades.begin(), grades.end()) / count;
|
|
}
|
|
|
|
private:
|
|
std::vector <double> grades;
|
|
};
|
|
|
|
class University {
|
|
public:
|
|
std::string name;
|
|
UniWorker* dean;
|
|
|
|
University(std::string name) {
|
|
this->name = name;
|
|
}
|
|
|
|
UniWorker* create_worker(std::string mem_name) {
|
|
int id = members.size() + 1;
|
|
UniWorker* worker = new UniWorker(this, mem_name, id);
|
|
members.push_back(worker);
|
|
return worker;
|
|
}
|
|
|
|
UniStudent* create_student(std::string mem_name) {
|
|
int id = members.size() + 1;
|
|
UniStudent* student = new UniStudent(this, mem_name, id);
|
|
members.push_back(student);
|
|
return student;
|
|
}
|
|
|
|
void elect_dean(UniWorker* worker) {
|
|
dean = worker;
|
|
}
|
|
|
|
int count_members() {
|
|
return members.size();
|
|
}
|
|
private:
|
|
std::vector <UniMember*> members;
|
|
};
|
|
|
|
|
|
int main() {
|
|
University* trier = new University("Trier");
|
|
UniWorker* dean = trier->create_worker("Eva Eckkrammer");
|
|
trier->elect_dean(dean);
|
|
UniStudent* student = trier->create_student("Jan-Niclas Loosen");
|
|
student->evaluate_exam(1.3);
|
|
student->evaluate_exam(2.3);
|
|
student->evaluate_exam(1.3);
|
|
student->evaluate_exam(3.3);
|
|
|
|
std::cout << "Die Universitaet " << trier->name << " hat " << trier->count_members() << " Mitglieder." << std::endl;
|
|
std::cout << "Die Dekanin der Universitaet " << trier->name << " heisst " << trier->dean->name << "." << std::endl;
|
|
std::cout << student->name << " hat einen Notenschnitt von " << student->calc_avg() << "." << std::endl;
|
|
}
|
|
|
|
|
|
|