From 04a640c8addc58b3e43a5067cd9a6f8ec726c3b9 Mon Sep 17 00:00:00 2001 From: Alexander Steinmaurer <a@steinmaurer.cc> Date: Thu, 20 May 2021 17:24:20 +0200 Subject: [PATCH] Lecture 9 --- .../vo/stream-09/01-multiple-inheritance.cpp | 45 ++++++++++++++++++ 2021-oop1/vo/stream-09/02-ambiguous.cpp | 47 +++++++++++++++++++ 2021-oop1/vo/stream-09/03-diamond-problem.cpp | 30 ++++++++++++ .../vo/stream-09/04-diamond-solution.cpp | 29 ++++++++++++ .../vo/stream-09/05-heroes-and-enemies-1.cpp | 26 ++++++++++ 2021-oop1/vo/stream-09/06-composition.cpp | 29 ++++++++++++ 6 files changed, 206 insertions(+) create mode 100644 2021-oop1/vo/stream-09/01-multiple-inheritance.cpp create mode 100644 2021-oop1/vo/stream-09/02-ambiguous.cpp create mode 100644 2021-oop1/vo/stream-09/03-diamond-problem.cpp create mode 100644 2021-oop1/vo/stream-09/04-diamond-solution.cpp create mode 100644 2021-oop1/vo/stream-09/05-heroes-and-enemies-1.cpp create mode 100644 2021-oop1/vo/stream-09/06-composition.cpp diff --git a/2021-oop1/vo/stream-09/01-multiple-inheritance.cpp b/2021-oop1/vo/stream-09/01-multiple-inheritance.cpp new file mode 100644 index 0000000..736749a --- /dev/null +++ b/2021-oop1/vo/stream-09/01-multiple-inheritance.cpp @@ -0,0 +1,45 @@ +#include <iostream> +#include <string> + +class Muggle { + private: + std::string job_; + + public: + Muggle(std::string job) : job_(job) { } + + std::string getJob () const { + return job_; + } +}; + +class Wizard { + private: + std::string house_; + + public: + Wizard(std::string house) : house_(house) { } + + std::string getHouse () const { + return house_; + } +}; + +class Halfblood : public Muggle, public Wizard { + private: + bool isMotherMuggle_; + bool isFatherMuggle_; + + public: + Halfblood(std::string job, std::string house, + bool muggleMother, bool muggleFather) : Muggle(job), + Wizard(house), isMotherMuggle_(muggleMother), + isFatherMuggle_(muggleFather) { } +}; + +int main() +{ + Halfblood severus_snape("Teacher", "Slytherin", false, true); + + return 0; +} \ No newline at end of file diff --git a/2021-oop1/vo/stream-09/02-ambiguous.cpp b/2021-oop1/vo/stream-09/02-ambiguous.cpp new file mode 100644 index 0000000..634a67a --- /dev/null +++ b/2021-oop1/vo/stream-09/02-ambiguous.cpp @@ -0,0 +1,47 @@ +#include <iostream> +#include <string> + +class Muggle { + private: + std::string name_; + + public: + Muggle(std::string name) : name_(name) { } + + std::string getName () const { + return name_; + } +}; + +class Wizard { + private: + std::string name_; + + public: + Wizard(std::string name) : name_(name) { } + + std::string getName () const { + return name_; + } + }; + + class Halfblood : public Muggle, public Wizard { + private: + bool isMotherMuggle_; + bool isFatherMuggle_; + + public: + Halfblood(std::string m_name, std::string w_name, + bool muggleMother, bool muggleFather) : Muggle(m_name), + Wizard(w_name), isMotherMuggle_(muggleMother), + isFatherMuggle_(muggleFather) {} + }; + + int main() + { + Halfblood he_who_must_not_be_named("Tom Riddle", "Lord Voldemort", + false, true); + std::cout << he_who_must_not_be_named.getName(); + + return 0; + } \ No newline at end of file diff --git a/2021-oop1/vo/stream-09/03-diamond-problem.cpp b/2021-oop1/vo/stream-09/03-diamond-problem.cpp new file mode 100644 index 0000000..18642ed --- /dev/null +++ b/2021-oop1/vo/stream-09/03-diamond-problem.cpp @@ -0,0 +1,30 @@ +#include <iostream> +#include <string> + +struct Person { + Person() { std::cout << "Person Konstruktor" << std::endl; } +}; + +struct Muggle : public Person { + Muggle() { std::cout << "Muggle Konstruktor" << std::endl; } +}; + + +struct Wizard : public Person { + Wizard() { std::cout << "Wizard Konstruktor" << std::endl; } +}; + + +struct Halfblood : public Muggle, public Wizard { + Halfblood() { std::cout << "Halfblood Konstruktor" << std::endl; } +}; + +int main() +{ + Halfblood he_who_must_not_be_named; +} +//Person Konstruktor +//Muggle Konstruktor +//Person Konstruktor +//Wizard Konstruktor +//Halfblood Konstruktor \ No newline at end of file diff --git a/2021-oop1/vo/stream-09/04-diamond-solution.cpp b/2021-oop1/vo/stream-09/04-diamond-solution.cpp new file mode 100644 index 0000000..65f5e62 --- /dev/null +++ b/2021-oop1/vo/stream-09/04-diamond-solution.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include <string> + +struct Person { + Person() { std::cout << "Person Konstruktor" << std::endl; } +}; + +struct Muggle : virtual public Person { + Muggle() { std::cout << "Muggle Konstruktor" << std::endl; } +}; + + +struct Wizard : virtual public Person { + Wizard() { std::cout << "Wizard Konstruktor" << std::endl; } +}; + + +struct Halfblood : public Muggle, public Wizard { + Halfblood() { std::cout << "Halfblood Konstruktor" << std::endl; } +}; + +int main() +{ + Halfblood he_who_must_not_be_named; +} +//Person Konstruktor +//Muggle Konstruktor +//Wizard Konstruktor +//Halfblood Konstruktor \ No newline at end of file diff --git a/2021-oop1/vo/stream-09/05-heroes-and-enemies-1.cpp b/2021-oop1/vo/stream-09/05-heroes-and-enemies-1.cpp new file mode 100644 index 0000000..a6125aa --- /dev/null +++ b/2021-oop1/vo/stream-09/05-heroes-and-enemies-1.cpp @@ -0,0 +1,26 @@ +#include <iostream> +#include <string> + +struct Species { + void fly() { } +}; + +struct Human : Species { + std::string blood_group; +}; + +struct Kree : public Species { + //Kree things +}; + +struct Titan : public Species { + //Titan things +}; + +struct Hero : Human Human { + //Hero things +}; + +struct Enemie : public Human, public Kree, public Titan { + void makeEvilPlans() { } +}; \ No newline at end of file diff --git a/2021-oop1/vo/stream-09/06-composition.cpp b/2021-oop1/vo/stream-09/06-composition.cpp new file mode 100644 index 0000000..a844b01 --- /dev/null +++ b/2021-oop1/vo/stream-09/06-composition.cpp @@ -0,0 +1,29 @@ +class Helmet { +}; + +class Arm { + void raise() {} +}; + +class Legs { + void move() {} +}; + +class Corpus { +}; + +class Weapon { + void ShootRocket() {} +}; + +class Mark { + Helmet h; + Corpus c; + Arm arms[2]; + Legs legs[2]; +}; + +int main() +{ + Mark mark1; +} \ No newline at end of file -- GitLab