fertig mit aufgabe 7

This commit is contained in:
Tobias Kachel 2026-06-09 14:55:01 +02:00
parent 5c0724bea0
commit f434fb7a3d
10 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,9 @@
#include "Klavier.h" #include "Klavier.h"
#include "Musikinstrument.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
Klavier::Klavier() { cout << "Konstruktor: Klavier()" << endl; } Klavier::Klavier() : Musikinstrument("Klavier") {
cout << "Konstruktor: Klavier()" << endl;
}
Klavier::~Klavier() { cout << "Destruktor: ~Klavier()" << endl; } Klavier::~Klavier() { cout << "Destruktor: ~Klavier()" << endl; }
void Klavier::spielen() const { cout << "Klavier klimpert" << endl; } void Klavier::spielen() const { cout << "Klavier klimpert" << endl; }

View File

@ -10,7 +10,7 @@ Musiker::Musiker(string name) {
cout << "Konstruktor: Musiker(string name): " << name << endl; cout << "Konstruktor: Musiker(string name): " << name << endl;
} }
Musiker::~Musiker() { Musiker::~Musiker() {
cout << "Destruktor: ~Musiker()" << endl; cout << "Destruktor: ~Musiker() : " << name << endl;
delete this->instrument; delete this->instrument;
} }
string Musiker::liefereName() { return name; } string Musiker::liefereName() { return name; }
@ -20,4 +20,5 @@ void Musiker::spielen() const {
} }
void Musiker::weiseInstrumentZu(Musikinstrument const *instrument) { void Musiker::weiseInstrumentZu(Musikinstrument const *instrument) {
this->instrument = instrument; this->instrument = instrument;
cout << name << " erhält " << instrument->liefereName() << endl;
} }

View File

@ -3,6 +3,7 @@
using namespace std; using namespace std;
Musikinstrument::Musikinstrument() { Musikinstrument::Musikinstrument() {
this->name = "Irgendein Musikinstrument";
cout << "Konstruktor: Musikinstrument()" << endl; cout << "Konstruktor: Musikinstrument()" << endl;
} }
Musikinstrument::Musikinstrument(string name) { Musikinstrument::Musikinstrument(string name) {
@ -10,7 +11,7 @@ Musikinstrument::Musikinstrument(string name) {
cout << "Konstruktor: Musikinstrument(string name): " << name << endl; cout << "Konstruktor: Musikinstrument(string name): " << name << endl;
} }
Musikinstrument::~Musikinstrument() { Musikinstrument::~Musikinstrument() {
cout << "Destruktor: Irgentein Musikinstrument" << endl; cout << "Destruktor: ~Musikinstrument : " << name << endl;
} }
void Musikinstrument::spielen() const { void Musikinstrument::spielen() const {
cout << "Irgentein Musikinstrument erklingt irgentwie" << endl; cout << "Irgentein Musikinstrument erklingt irgentwie" << endl;

View File

@ -2,8 +2,8 @@
#include "Musikinstrument.h" #include "Musikinstrument.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
Trompete::Trompete() { Trompete::Trompete() : Musikinstrument("Trompete") {
Musikinstrument("Trompete"); cout << "Konstruktor: Trompete()" << endl;
cout << "Konstruktor: Trompete()" << endl; } }
Trompete::~Trompete() { cout << "Destruktor: ~Trompete()" << endl; } Trompete::~Trompete() { cout << "Destruktor: ~Trompete()" << endl; }
void Trompete::spielen() const { cout << "Trompete trötet" << endl; } void Trompete::spielen() const { cout << "Trompete trötet" << endl; }

Binary file not shown.