Пример #1
0
/******************************************************************************
	name:        void writeRomDataToFile(ofstream &)
	description: Writes data about a specific room to file:
					Room number
					Number of beds
					Breakfast included
					Reservation(s)
	parameters:  (ofstream) & file
	returns:     n/a
******************************************************************************/
void Rom::writeRomDataToFile(ofstream & outFile)
{
	outFile << roomNumber << "\n" << numberOfBeds << "\n" << (breakfastIncluded ? 1 : 0 )<< "\n";
	outFile << Reservations->no_of_elements() << "\n";
		for (int i = 1; i <= Reservations->no_of_elements(); i++)
		{
			Reservasjon* temp = (Reservasjon*) Reservations->remove_no(i);
			Reservations->add(temp);
			temp->writeDataToFile(outFile);
		}
}
Пример #2
0
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);
}