Commit 735769a4 authored by Felix Huther's avatar Felix Huther
Browse files

test

parent d1d98a22
......@@ -8,10 +8,12 @@ SOURCES += \
hdamember.cpp \
lecturemember.cpp \
main.cpp \
student.cpp
student.cpp \
university.cpp
HEADERS += \
Lecturer.h \
hdamember.h \
lecturemember.h \
student.h
student.h \
university.h
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.0, 2022-05-06T19:08:17. -->
<!-- Written by QtCreator 4.15.0, 2022-05-06T19:31:06. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -4,40 +4,45 @@
#include "Lecturer.h"
#include "hdamember.h"
#include "lecturemember.h"
#include "university.h"
using namespace std;
int main()
{
Student stud1;
University uni;
uni.printAllMembers();
cin >> stud1;
hdaMember* dozent = new Lecturer ("Herr Mayer");
hdaMember* member = new lectureMember("SimpleGuy",true);
std::vector<hdaMember*> hoersaal = { dozent,member};
for(auto members: hoersaal){
members->PrintName();
}
// Student stud1;
// cin >> stud1;
// hdaMember* dozent = new Lecturer ("Herr Mayer");
// hdaMember* member = new lectureMember("SimpleGuy",true);
// std::vector<hdaMember*> hoersaal = { dozent,member};
Student* Felix = new Student("Felix",true,3);
Student* Sven = new Student("Sven",true,3);
Student* Atta = new Student("Atta",false);
// for(auto members: hoersaal){
// members->PrintName();
// }
std::vector<Student*> students ={Felix,Sven,Atta};
for(auto student : students)
{
cout << *(student) << endl;
++(*student);
}
// Student* Felix = new Student("Felix",true,3);
// Student* Sven = new Student("Sven",true,3);
// Student* Atta = new Student("Atta",false);
for(auto student : students) // every student got up one semester check
{
cout << *(student) << endl;
++(*student);
}
// std::vector<Student*> students ={Felix,Sven,Atta};
// for(auto student : students)
// {
// cout << *(student) << endl;
// ++(*student);
// }
// for(auto student : students) // every student got up one semester check
// {
// cout << *(student) << endl;
// ++(*student);
// }
return 0;
}
......@@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, const Student& student)
}
std::istream& operator>>(std::istream& is,Student& student)
{ std::cout << "Enter Name and Semester\n";
{
is >> student.name >> student.currentSemester;
return is;
}
......
#include "university.h"
University::University()
{
hdaMember* dozent = new Lecturer ("Herr Mayer");
hdaMember* student1 = new Student("Felix",true);
hdaMember* student2 = new Student("Sven",true);
hdaMember* student3 = new Student("Atta",false);
hdaMembers.push_back(dozent);
hdaMembers.push_back(student1);
hdaMembers.push_back(student2);
hdaMembers.push_back(student3);
}
void University::printAllMembers() const
{
for(hdaMember* member : hdaMembers)
{
member->PrintName();
}
}
University& University::operator=(University other){
this->hdaMembers = other.hdaMembers;
return *this;
}
#ifndef UNIVERSITY_H
#define UNIVERSITY_H
#include<vector>
#include "hdamember.h"
#include "Lecturer.h"
#include "student.h"
class University
{
public:
University();
University(University& other);
University &operator=(University other);
void printAllMembers() const;
private:
std::vector<hdaMember*> hdaMembers;
};
#endif // UNIVERSITY_H
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
Lecturer.cpp \
hdamember.cpp \
lecturemember.cpp \
main.cpp \
student.cpp \
university.cpp
HEADERS += \
Lecturer.h \
hdamember.h \
lecturemember.h \
student.h \
university.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()
{
if(typeid (this) == typeid (Student)){
Student::PrintName();
}
else if(typeid (this)== typeid (Lecturer)){
Lecturer::PrintName();
}
else std::cout << "My name is " << name <<
" and i'm a simple member\n";
}
#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()
{
std::vector<hdaMember*> hoersaal = { dozent,student1,student2,student3,member};
for(auto members: hoersaal){
members->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
#include "university.h"
University::University()
{
hdaMember* dozent = new Lecturer ("Herr Mayer");
hdaMember* student1 = new Student("Felix",true);
hdaMember* student2 = new Student("Sven",true);
hdaMember* student3 = new Student("Atta",false);
hdaMembers.push_back(dozent);
hdaMembers.push_back(student1);
hdaMembers.push_back(student2);
hdaMembers.push_back(student3);
}
void University::printAllMembers() const
{
for(hdaMember* member : hdaMembers)
{
member->PrintName();
}
}
const std::vector<hdaMember*>& University::getMembers() const{
return hdaMembers;
}
University& University::operator=(University other){
hdaMembers.swap(other.hdaMembers);
return *this;
}
#ifndef UNIVERSITY_H
#define UNIVERSITY_H
#include <vector>
#include "student.h"
#include "Lecturer.h"
#include "hdamember.h"
class Student;
class Lecturer;
class hdaMember;
class University
{
public:
University();
University(const University& other);
~University();
void printAllMembers() const;
const std::vector<hdaMember*>& getMembers() const;
University& operator=(University other);
private:
std::vector<hdaMember*> hdaMembers;
};
#endif // UNIVERSITY_H
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.0, 2022-04-28T22:51:17. -->
<!-- Written by QtCreator 4.15.0, 2022-05-11T18:18:14. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
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