From ad6d253e3eca1178d988a71ff03af994ef70aecf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 6 May 2022 11:31:49 +0300 Subject: Autocommit at 06.05.2022 @ 11:31 --- src/VenueConsoleUI.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/VenueConsoleUI.cpp') diff --git a/src/VenueConsoleUI.cpp b/src/VenueConsoleUI.cpp index 092ead4..fdac1bc 100644 --- a/src/VenueConsoleUI.cpp +++ b/src/VenueConsoleUI.cpp @@ -48,28 +48,18 @@ void command_freeSeats() { OrderedList tickets = v->get_es().queryTickets(name, date); OrderedList reservations = v->get_es().queryReservations(name, date); - unsigned tableSize = hall->get_rowCount() * hall->get_seatsPerRow(), - nextTInd = 0, nextRInd = 0, - nextT = 0, nextR = 0; - - if (tickets.get_count() > 0) - nextT = (tickets[nextT].get_row() - 1) * hall->get_seatsPerRow() + tickets[nextT].get_seat() - 1; - if (reservations.get_count() > 0) - nextR = (reservations[nextR].get_ticket().get_row() - 1) * hall->get_seatsPerRow() + reservations[nextT].get_ticket().get_seat() - 1; - + unsigned tableSize = hall->get_rowCount() * hall->get_seatsPerRow(); char tableData[tableSize + 1]; - for (unsigned i = 0; i < tableSize; i++) { - if (nextTInd < tickets.get_count() && nextT == i) { - tableData[i] = 'B'; - nextTInd++; - nextT = (tickets[nextT].get_row() - 1) * hall->get_seatsPerRow() + tickets[nextT].get_seat() - 1; - } - else if (nextRInd < reservations.get_count() && nextR == i) { - tableData[i] = 'R'; - nextRInd++; - nextR = (reservations[nextR].get_ticket().get_row() - 1) * hall->get_seatsPerRow() + reservations[nextT].get_ticket().get_seat() - 1; + + for (unsigned ind = 0, row = 1; row < hall->get_rowCount(); row++) { + for (unsigned seat = 1; seat < hall->get_seatsPerRow(); seat++, ind++) { + if (tickets.contain(Ticket(row, seat))) + tableData[ind] = 'B'; + else if (reservations.contain(Ticket(row, seat))) + tableData[ind] = 'R'; + else + tableData[ind] = ' '; } - else tableData[i] = ' '; } tableData[tableSize] = '\0'; -- cgit v1.3.1-23-gd82d