64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
/**
|
|
* OPR-Praktikum SS 2013
|
|
* Aufgabe 5
|
|
* Vorgegebene Datei
|
|
* Autor: Thomas Mahr
|
|
**/
|
|
|
|
#include "Klavier.h"
|
|
#include "Trompete.h"
|
|
#include "Orchester.h"
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#include <climits>
|
|
#include <iostream>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
Musikinstrument* musikinstrumentZufaelligErzeugen()
|
|
{
|
|
Musikinstrument* musikinstrument;
|
|
int r = rand()%3;
|
|
switch(r)
|
|
{
|
|
case 0:
|
|
musikinstrument = new Klavier();
|
|
break;
|
|
case 1:
|
|
musikinstrument = new Trompete();
|
|
break;
|
|
default:
|
|
musikinstrument = new Musikinstrument();
|
|
break;
|
|
}
|
|
return musikinstrument;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
srand(time(0));
|
|
|
|
Orchester orchester;
|
|
|
|
int n;
|
|
cout << "Wieviele Musiker sollen im Orchester spielen? ";
|
|
cin >> n;
|
|
cin.ignore(INT_MAX,'\n'); // entfernt übriggebliebenen Zeilenumbruch der letzten Eingabe
|
|
|
|
cout << "+++ Orchester mit " << n << " Musikern besetzen\n";
|
|
for(int i=0; i<n; i++)
|
|
{
|
|
cout << "Wie heißt der " << i+1 << ". Musiker? ";
|
|
string name;
|
|
getline(cin,name);
|
|
Musiker* musiker = new Musiker(name);
|
|
orchester.hinzufuegen(musiker);
|
|
musiker->weiseInstrumentZu(musikinstrumentZufaelligErzeugen());
|
|
}
|
|
|
|
cout << "+++ Das Konzert beginnt\n";
|
|
orchester.spielen();
|
|
|
|
cout << "+++ Applaus\n";
|
|
}
|