Unverified Commit 530f890f authored by Minhphucnguyen49's avatar Minhphucnguyen49 Committed by GitHub
Browse files

Add files via upload

parent e7558196
#include "Lecturer.h"
Lecturer::Lecturer(std::string name_in)
:hdaMember(name_in)// because lecuterer is also a hdaMember => explicit constructor is being used
{}
void Lecturer::talk()
{
static int count {0};
if ( count < 5 )
{
std::cout << "PG2 is very important!" << std::endl;
count ++;
talk();
}
else
{
count = 0;
}
}
void Lecturer::myName()
{
std::cout << "my Name is " << name << " and I am a Lecturer" << std::endl;
}
#ifndef LECTURER_H
#define LECTURER_H
#include "hdaMember.h"
class Lecturer : public hdaMember
{
public:
Lecturer(std::string name);
void talk();
void myName() override;
private:
};
#endif // LECTURER_H
#include "Student.h"
void Student::myName()
{
std::cout << "my name is " << name << " and I am studying here." << std::endl;
}
Student::Student(std::string name, bool isListening)
: hdaMember(name), isListening(isListening)
{}
void Student::listens()
{
if (isListening)
{
std::cout << "aha" << std::endl;
}
else
std::cout << "zZz" << std::endl;
}
#ifndef STUDENT_H
#define STUDENT_H
#include "hdaMember.h"
class Student : public hdaMember
{
public:
Student (std::string name, bool isListening);
void listens();
void myName() override;
private:
bool isListening;
};
#endif // STUDENT_H
#include "hdaMember.h"
hdaMember::hdaMember(std::string name_in)//explicit constructor
: name(name_in), isHappy(true)// constant bool isHappy = true initialisiert
{}
void hdaMember::myName()
{
std::cout << "my Name is: " << name << std::endl;
}
#ifndef HDAMEMBER_H
#define HDAMEMBER_H
#include <iostream>
class hdaMember
{
public:
explicit hdaMember( std::string name );// explicit constructor //nur ein Parameter => explicit (schon gelernt)
virtual ~hdaMember(){};//abstract destructor
virtual void myName();//print out in console Names and Subclasses
protected://hier should be protected because we are using the Vererbungstruktur,
//if private is used, then "name" in student.cpp can't not be seen
std::string name;
const bool isHappy;
};
#endif // HDAMEMBER_H
#include "hdaMember.h"
#include "Student.h"
#include "Lecturer.h"
#include <vector>
int main()
{
std::vector<hdaMember*> members{};
members.push_back(new Lecturer("Benjamin Meyer"));
members.push_back( new Student("a b", true));
members.push_back( new Student("c d", false));
for (auto m : members)
{
m->myName();
}
}
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