Mi código sirve para reservar los asientos de un vuelo determinado y que luego otros asientos sean llenados todo esta en una clase que selecciona los asientos y luego funciona con otra clase que selecciona los vuelos. Lo que hace la clase de asientos es generar un array para cada columna de asientos llenarlos de letras 'E' y tras los input del usuario llenar el determinado asiento con una 'R'.
Este proceso funciona bien para el primer input sin embargo cuando el usuario quiere llenar otro asiento se pierden los valores almacenados en el array.
void seat_initializer (){
static bool initialized;
if (!initialized ){
initialized = true;
for (int i = 0; i <= 4; ++i) {
column_A_NYCT13[i] = 'E';
column_B_NYCT13[i] = 'E';
column_C_NYCT13[i] = 'E';
column_D_NYCT13[i] = 'E';
}
}
}
void seat_printer(){
cout << "x AB | CD " << endl;
cout << "0 " << column_A_NYCT13[0] << column_B_NYCT13[0] << " | " << column_C_NYCT13[0] << column_D_NYCT13[0] << endl;
cout << "1 " << column_A_NYCT13[1] << column_B_NYCT13[1] << " | " << column_C_NYCT13[1] << column_D_NYCT13[1] << endl;
cout << "2 " << column_A_NYCT13[2] << column_B_NYCT13[2] << " | " << column_C_NYCT13[2] << column_D_NYCT13[2] << endl;
cout << "3 " << column_A_NYCT13[3] << column_B_NYCT13[3] << " | " << column_C_NYCT13[3] << column_D_NYCT13[3] << endl;
cout << "4 " << column_A_NYCT13[4] << column_B_NYCT13[4] << " | " << column_C_NYCT13[4] << column_D_NYCT13[4] << endl;
}
void instruction_for_seats(){
cout << "Now please see the order of the seats. \nThe columns A and D represents the window seats. \nThe columns B and C represents the hall seats.\nThe seats with the letter E represents the seats that are empty.\n"<< endl;
seat_printer();
cout <<endl;
cout << "Please choose the correspondent letter for the column you want the seat for the flight NYCT13"<< endl;
}
void set_seats_window(char control_window) {
int chosen_seat;
if (control_window == 'A' || control_window == 'a') {
for (int return_to_number = 1;;) {
cout << "Please enter the number of the seat you want" << endl;
cin >> chosen_seat;
if (chosen_seat <= 4) {
cout << "You have chosen the seat A" << chosen_seat << "\nAre you sure you want to reserve this seat?\nType A to accept or C to cancell." << endl;
cin >> seat_confirmation_NYCT13;
if (seat_confirmation_NYCT13 == 'A' || seat_confirmation_NYCT13 == 'a'){
cout <<"Your selection was saved."<<endl;
column_A_NYCT13[chosen_seat] = 'R';
break;
}
if (seat_confirmation_NYCT13 == 'C' || seat_confirmation_NYCT13 == 'c'){
cout << "Your selection was cancelled"<<endl;
}
}else {
cout << "Invalid entry.\a"<<endl;
continue;
}
}
}
if (control_window == 'D' || control_window == 'd') {
for (int return_to_number = 1;;) {
cout << "Please enter the number of the seat you want" << endl;
cin >> chosen_seat;
if (chosen_seat <= 4) {
cout << "You have chosen the seat A" << chosen_seat << "\nAre you sure you want to reserve this seat?\nType A to accept or C to cancell." << endl;
cin >> seat_confirmation_NYCT13;
if (seat_confirmation_NYCT13 == 'A' || seat_confirmation_NYCT13 == 'a'){
cout <<"Your selection was saved."<<endl;
column_D_NYCT13[chosen_seat] = 'R';
break;
}
if (seat_confirmation_NYCT13 == 'C' || seat_confirmation_NYCT13 == 'c'){
cout << "Your selection was cancelled"<<endl;
}
}else {
cout << "Invalid entry.\a"<<endl;
continue;
}
}
}
}
void set_seats_hall(char control_hall){
int chosen_seat;
if (control_hall == 'B' || control_hall == 'b') {
for (int return_to_number = 1;;) {
cout << "Please enter the number of the seat you want" << endl;
cin >> chosen_seat;
column_B_NYCT13[chosen_seat] = 'R';
if (chosen_seat <= 4) {
cout << "You have chosen the seat B" << chosen_seat << "\nAre you sure you want to reserve this seat?\nType A to accept or C to cancell."<< endl;
cin >> seat_confirmation_NYCT13;
if (seat_confirmation_NYCT13 == 'A' || seat_confirmation_NYCT13 == 'a') {
cout << "Your selection was saved for the reservation." <<endl;
break;
}
if (seat_confirmation_NYCT13 == 'C' || seat_confirmation_NYCT13 == 'c') {
cout << "Your selection was cancelled.";
}
} else {
cout << "Invalid entry. \a";
continue;
}
}
}
if (control_hall == 'C' || control_hall == 'c') {
for (int return_to_number = 1;;) {
cout << "Please enter the number of the seat you want" << endl;
cin >> chosen_seat;
column_C_NYCT13[chosen_seat] = 'R';
if (chosen_seat <= 4) {
cout << "You have chosen the seat B" << chosen_seat << "\nAre you sure you want to reserve this seat?\nType A to accept or C to cancell."<< endl;
cin >> seat_confirmation_NYCT13;
if (seat_confirmation_NYCT13 == 'A' || seat_confirmation_NYCT13 == 'a') {
cout << "Your selection was saved for the reservation." <<endl;
break;
}
if (seat_confirmation_NYCT13 == 'C' || seat_confirmation_NYCT13 == 'c') {
cout << "Your selection was cancelled.";
}
} else {
cout << "Invalid entry. \a";
continue;
}
}
}
}
private:
char column_A_NYCT13 [4];
char column_B_NYCT13 [4];
char column_C_NYCT13 [4];
char column_D_NYCT13 [4];
char seat_confirmation_NYCT13;