auf einen Sitz i in der Reihe j kannst du zugreifen mit
Code:
new_seat[j * iSitzanzahl + i]
Die Indizes beginnen dabei bei 0!
Ich würde aus dem Struct eine Klasse machen mit einem Default Konstruktor:
Code:
class seat {
public:
seat() : ist_belegt(false) {}
string Name, Vorname;
bool ist_belegt;
// int Sitz[0][0]; // was soll das?
};
public:
...
private:
vector<seat> seats;
Jetzt kannst du es elegant schreiben:
Code:
<Flight.h> // Header inkludieren nicht .cpp !
int iReihe = 21;
int iSitzanzahl = 6;
Flight::Flight()
: seats(iReihe * iSitzanzahl) // alle Sitze mit default initialisieren
{
}
Flight::ausgeben()
{
for(int reihe(0); reihe < iReihe; ++reihe) {
std::out << std::endl << reihe + 1;
for(int sitz(0); sitz < iSitzanzahl; ++sitz)
std::out << seats[reihe * iSitzanzahl + sitz].ist_belegt ? " belegt" : " frei"; // Tip: Strings gleich lang machen
}
}
fertig.