diff options
Autocommit at 07.05.2022 @ 10:52
3 files changed, 17 insertions, 21 deletions
| -rw-r--r-- | src/Generic/String/String.cpp | 19 | ||||
| -rw-r--r-- | src/Services/EventService.cpp | 2 | ||||
| -rw-r--r-- | src/UserInterface/VenueConsoleUI.cpp | 17 |
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index 570a2c6..99c2e0c 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -3,6 +3,14 @@ /* Private */ +void String::resize() { + length *= 2; + char* newStr = new char[length]; + strncpy(newStr, str, count); + delete[] str; + str = newStr; +} + void String::free() { delete[] str; } @@ -17,9 +25,9 @@ void String::copyFrom(const String& other) { /* Public */ String::String(const char* str) { - count = length = strlen(str) + 1; // capture terminating zero - this->str = new char[length]; - strncpy(this->str, str, count); + count = length = strlen(str); + this->str = new char[length + 1]; // capture terminating zero + strncpy(this->str, str, count + 1); } const char* String::get_cstr() const { @@ -39,7 +47,10 @@ String& String::operator+=(const String& other) { } String& String::operator+=(char other) { - if () + if (count == length) resize(); + + str[count++] = other; + return *this; } String::String() : String("") {} diff --git a/src/Services/EventService.cpp b/src/Services/EventService.cpp index 27246d5..fc62c64 100644 --- a/src/Services/EventService.cpp +++ b/src/Services/EventService.cpp @@ -135,7 +135,7 @@ StatusCode EventService::buyTicket(const char* name, const Date& date, const Tic return Success; } -String EventService::createSeatingString(const char*name, const Date& date) { +String EventService::createSeatingString(const char* name, const Date& date) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) return ""; diff --git a/src/UserInterface/VenueConsoleUI.cpp b/src/UserInterface/VenueConsoleUI.cpp index 0029b17..04ad0a5 100644 --- a/src/UserInterface/VenueConsoleUI.cpp +++ b/src/UserInterface/VenueConsoleUI.cpp @@ -44,22 +44,7 @@ void command_freeSeats() { Date date; inputSubBox("Enter event date: ", &date); - OrderedList<Ticket> tickets = es->getTickets(name, date); - OrderedList<Reservation> reservations = es->getReservations(name, date); - - unsigned tableSize = hall->get_rowCount() * hall->get_seatsPerRow(); - char tableData[tableSize + 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] = ' '; - } - } + String seating = es->createSeatingString(name, date); tableData[tableSize] = '\0'; table(1, hall->get_seatsPerRow(), tableData); |
