Commit 58867fa7 authored by Felix Huther's avatar Felix Huther
Browse files

hoersaalUebung erweitert

parent eec8b070
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
Lecturer.cpp \
hdamember.cpp \
lecturemember.cpp \
main.cpp \
student.cpp
HEADERS += \
Lecturer.h \
hdamember.h \
lecturemember.h \
student.h
#include "Lecturer.h"
Lecturer::Lecturer(std::string name) : hdaMember(name)
{
}
void Lecturer::talk()
{
static int count = 0;
if(count < 5){
std::cout << "PG2 ist wichtig!\n";
count++;
talk();
}
else{
count = 0;
}
}
void Lecturer::PrintName()
{
std::cout << "My name is " << name << " and I'm teaching " << std::endl;
}
#ifndef LECTURER_H
#define LECTURER_H
#include "hdamember.h"
class Lecturer : virtual public hdaMember
{
public:
Lecturer(std::string name);
void talk();
void PrintName()override;
};
#endif // LECTURER_H
#include "hdamember.h"
hdaMember::hdaMember(std::string name)
:isHappy(true),name(name)
{
}
hdaMember::~hdaMember()
{
}
void hdaMember::PrintName()
{
std::cout << "My name is " << name << std::endl;
}
#ifndef HDAMEMBER_H
#define HDAMEMBER_H
#include <iostream>
class hdaMember
{
public:
explicit hdaMember(std::string name);
virtual ~hdaMember(); // really important, otherwise we get alot of data leaks
virtual void PrintName();
protected:
const bool isHappy;
std::string name;
};
#endif // HDAMEMBER_H
#include "lecturemember.h"
lectureMember::lectureMember(std::string name,bool isListening)
:hdaMember(name),Student(name,isListening),Lecturer(name)
{
}
void lectureMember::PrintName()
{
std::cout << "Hallo";
}
#ifndef LECTUREMEMBER_H
#define LECTUREMEMBER_H
#include "student.h"
#include "Lecturer.h"
class lectureMember : public Student, public Lecturer
{
public:
lectureMember(std::string name,bool isListening);
// hdaMember interface
public:
void PrintName() override;
};
#endif // LECTUREMEMBER_H
#include <iostream>
#include <vector>
#include "student.h"
#include "Lecturer.h"
#include "hdamember.h"
#include "lecturemember.h"
using namespace std;
int main()
{
hdaMember* dozent = new Lecturer ("Herr Mayer");
hdaMember* student1 = new Student("Felix",true);
hdaMember* student2 = new Student("Sven",true);
hdaMember* student3 = new Student("Atta",false);
std::vector<hdaMember*> hoersaal = { dozent,student1,student2,student3};
for(auto members: hoersaal){
members->PrintName();
}
lectureMember lm("Herr Mayer",true);
lm.PrintName();
return 0;
}
#include "student.h"
Student::Student(std::string name, bool isListening) : hdaMember(name),isListening(isListening)
{
}
void Student::listens()const
{
isListening? std::cout << "aha\n" : std::cout << "zZz\n";
}
void Student::PrintName()
{
std::cout << "My name is " << name << " and i study " << std::endl;
}
#ifndef STUDENT_H
#define STUDENT_H
#include "hdamember.h"
class Student : virtual public hdaMember
{
public:
Student(std::string name, bool isListening);
void listens() const ;
void PrintName() override;
private:
bool isListening;
};
#endif // STUDENT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment