/****************************************************************************** name: void listReservationsGaps description: The inverse of listReservations -- instead of listing when the room is reserved, it lists the gaps between reservations, to display when the room is NOT reserved parameters: n/a returns: n/a ******************************************************************************/ void Rom::listReservationsGaps() { int availableFrom = tid.hent_dato(), nextArrival = 0; Reservasjon* temp = nullptr; for(int i = 1; i <= Reservations->no_of_elements(); i++) { temp = (Reservasjon*) Reservations->remove_no(i); Reservations->add(temp); if(temp->getArrival() <= availableFrom && temp->getDeparture() > tid.hent_dato()) availableFrom = temp->getDeparture(); else if(temp->getDeparture() < availableFrom) availableFrom = tid.hent_dato(); else if(temp->getArrival() > availableFrom) nextArrival = temp->getArrival(); if(nextArrival > availableFrom) cout << "\nRoom #" << temp->getRoomID() << " is available from " << availableFrom << "-" << nextArrival; availableFrom = temp->getDeparture(); } if(((availableFrom > 0 && nextArrival == 0) ||( availableFrom > 0 && nextArrival < availableFrom) && temp != nullptr)) { cout << "\nRoom #" << temp->getRoomID() << " is available from " << availableFrom; cin.get(); } }
Reservasjon* Rom::reservationByDate(int date, int action) { extern Hotell* hotellet; for (int i = 1; i <= Reservations->no_of_elements(); i++) { Reservasjon* temp = (Reservasjon*) Reservations->remove_no(i); // If this method was called with action CHECKOUT and departure date is the provided date for the reservation, // or action was checkin and arrival date is the date of this reservation, then return the reservation if ((action == CHECKOUT) || (action == CHECKIN && temp->getArrival() == date)) { // If action is checkout, destroy reservation, and create a temporary reservation object with errorcode // "reservation has been pruned" to be returned if(action == CHECKOUT && temp->getDeparture() == date) { temp->display(); if(readChar("Confirm checkout?",'y','n')=='y') { // Get filename, subtract file ending and apply new filename std::string hotellHst = hotellet->getFilename().substr(0, hotellet->getFilename().size()-4); hotellHst += ".hst"; // ... aaaand output! std::ofstream o(hotellHst.c_str(), std::ios::out|ios::app); temp->writeDataToFile(o); Reservations->destroy(temp->getRoomID()); temp = new Reservasjon(reservationHasBeenPruned); } // Otherwise, put it back in the list else Reservations->add(temp); } // If action is checkout, and a reservation on the room is current, but departure on reservation is not today, // ask if we want to check him out earlier than planned, and if so, call this method with his/her planned // departure date else if(action == CHECKOUT && temp->getDeparture() >= date && temp->getArrival() <= date) { std::cout << "\nGuest in room " << temp->getRoomID() << " is not meant to check out until " << temp->getDeparture(); if(readChar("\nCheck out anyways?",'y','n') == 'y') { Reservations->add(temp); return reservationByDate(temp->getDeparture(), CHECKOUT); } } // If action is check in, ask for confirmation to check in, and display information about the reservation else if(action == CHECKIN && readChar("Check-in?",'y','n') == 'y') { temp->display(); temp->setCheckin(); Reservations->add(temp); } // Otherwise, put it back in our list else { Reservations->add(temp); } return temp; } // If the method was called with NOOP action, as in NO OPeration, display the data without modifying it; essentially the same as // checkin, except it ONLY displays data about the reservation, and date may be any date within the time period of the reservation, // as opposed to requiring a specific checkin date. It does however require guests to be checked in. else if (action == NOOP && temp->getDeparture() >= date && temp->getArrival() <= date && temp->getInUse() == true) { //temp->display(roomNumber); Reservations->add(temp); return temp; } } // If no matching reservation was found, return a new reservations object, with // roomID containing the errorcode return new Reservasjon(reservationDoesNotExist); }