/**************************************************** Ed Yakabosky CSE 120 Section 002 This is the final project for CSE 120. In this program, a file of holidays and a file of magicians is read in, and a user inputs individual appointments for customers by holiday - and a magician is automatically assigned. If a holiday is fully booked, the customer is added to a waitlist. Users can also cancel appointments, add magicians, removed magicians, and check the status of each item - and the appropriate allocations are always made. input: magicians.txt, holidays.txt, schedule.txt, user prompts. output: 1: schedule, 2: CancelAppt, 3: NewMagician, 4: DelMagician, 5: Schedule checks, 6: Quit, schedule.txt, logfile.txt ****************************************************/ #include "Database.h" void Database::RunProgram(Magician magicians, Holiday holidays, Waitlist waitlist, ofstream &logfile) { ReadIn(magicians, holidays, waitlist, logfile); // Reads in previous load. int choice = 0; while (choice != 6) // 6 is "quit." { system("cls"); cout << endl; logfile << "The main menu is displayed:" << endl; logfile << endl; logfile << "\tWelcome to Magician Database v 1.0!!!" << endl; logfile << "\t"; for (int i = 0; i < 37; i++) { logfile << "-"; } logfile << endl; logfile << "\tPlease select an option." << endl; logfile << endl; logfile << "\t1: Schedule an appointment" << endl; logfile << "\t2: Cancel an appointment" << endl; logfile << "\t3: Signup a new magician" << endl; logfile << "\t4: Delete a magician" << endl; logfile << "\t5: Check status" << endl; logfile << "\t6: Quit" << endl; logfile << endl; logfile << "\tEnter choice: " << endl; logfile << endl; cout << "Welcome to Magician Database v 1.0!!!" << endl; for (int i = 0; i < 37; i++) { cout << "-"; } cout << endl; cout << "Please select an option." << endl; cout << endl; cout << "1: Schedule an appointment" << endl; cout << "2: Cancel an appointment" << endl; cout << "3: Signup a new magician" << endl; cout << "4: Delete a magician" << endl; cout << "5: Check status" << endl; cout << "6: Quit" << endl; cout << endl; cout << "Enter choice: "; cin >> choice; cout << endl; switch (choice) { case 1: system("cls"); logfile << "The user inputs 1, and the ScheduleAppt() function is called." << endl; logfile << endl; ScheduleAppt(magicians, holidays, waitlist, logfile); for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; case 2: system("cls"); logfile << "The user inputs 2, and the CancelAppt() function is called." << endl; logfile << endl; CancelAppt(magicians, holidays, waitlist, logfile); for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; case 3: system("cls"); logfile << "The user inputs 3, and the NewMagician() function is called." << endl; logfile << endl; NewMagician(magicians, holidays, waitlist, logfile); cout << "Please press any key to return to main menu..." << endl; logfile << "The user presses any key to return to the main menu." << endl; logfile << endl; getch(); for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; case 4: system("cls"); logfile << "The user inputs 4, and the DelMagician() function is called." << endl; logfile << endl; DelMagician(magicians, holidays, waitlist, logfile); cout << "Please press any key to return to main menu..." << endl; logfile << "The user presses any key to return to the main menu." << endl; logfile << endl; getch(); for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; case 5: system("cls"); logfile << "The user inputs 5, and the CheckStatus() function is called." << endl; logfile << endl; CheckStatus(holidays.getHoliday(), magicians.getMagician(), waitlist.getWaitList(), logfile); for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; case 6: system("cls"); logfile << "The user inputs 6, and the EndFile() function is called." << endl; logfile << endl; EndFile(holidays.getHoliday(), magicians.getMagician(), waitlist.getWaitList(), logfile); cout << "Exiting program..." << endl; cout << endl; logfile << "Exiting program..." << endl; logfile << endl; for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; break; default: logfile << "The user inputs a value other than 1-6, and the main menu reloads." << endl; logfile << endl; break; // Simply reloads menu. "Ignores" incorrect input. } } } // Done and Error'd. void Database::ReadIn(Magician &magicians, Holiday &holidays, Waitlist &waitlist, ofstream &logfile) { ifstream fin; logfile << "All pre-existing aspects of the schedule are now being read-in..." << endl; logfile << endl; list a = holidays.getHoliday(); list b = magicians.getMagician(); HolidayStruct readinholiday; MagicianStruct readinmagician; fin.open("schedule.txt"); if (fin.fail()) // If first time running program. { logfile << "\tThis is the first time the program is being run, so holidays will be read in from Holidays.txt" << endl; logfile << endl; fin.close(); fin.clear(); fin.open("Holidays.txt"); while (!fin.eof()) // inputs holidays { fin >> readinholiday.holidayName; a.push_back(readinholiday); logfile << "\t\t" << readinholiday.holidayName << " is added to the holiday list." << endl; logfile << endl; } fin.close(); fin.clear(); logfile << "\tThis is the first time the program is being run, so magicians will be read in from Magicians.txt" << endl; logfile << endl; fin.open("Magicians.txt"); while (!fin.eof()) // inputs magicians names { fin >> readinmagician.magicianName; b.push_back(readinmagician); logfile << "\t\t" << readinmagician.magicianName << " is added to the magician list." << endl; logfile << endl; } fin.close(); holidays.setHoliday(a); magicians.setMagician(b); } else // If program has been run before. { int numMags; // Number of magicians. int numHols; // Number of holidays int numMagDates; // Number of dates each magician has scheduled. int numHolDates; // Number of holidays scheduled. int numWaits; // Length of waitlist. string holiday; string magician; string customer; list c = waitlist.getWaitList(); WaitingStruct readinwaitlist; // Reads in holidays. fin >> numHols; logfile << "\tThe following holiday appointments are read in:" << endl; logfile << endl; for (int i = 0; i < numHols; i++) { fin >> readinholiday.holidayName; fin >> numHolDates; logfile << "\t\t" << readinholiday.holidayName << ":" << endl; logfile << endl; for (int j = 0; j < numHolDates; j++) { fin >> customer; fin >> magician; logfile << "\t\t\t" << magician << " will perform for " << customer << " on " << readinholiday.holidayName << "." << endl; logfile << endl; readinholiday.HolidaySchedule[customer] = magician; } a.push_back(readinholiday); holidays.setHoliday(a); readinholiday.HolidaySchedule.clear(); } // Reads in magicians. fin >> numMags; logfile << "\tThe following magician appointments are read in:" << endl; logfile << endl; for (int i = 0; i < numMags; i++) { fin >> readinmagician.magicianName; fin >> numMagDates; logfile << "\t\t" << readinmagician.magicianName << ":" << endl; logfile << endl; for (int j = 0; j < numMagDates; j++) { fin >> holiday ; fin >> customer; logfile << "\t\t\t" << customer << " has an appointment on " << holiday << " with " << readinmagician.magicianName << "." << endl; logfile << endl; readinmagician.MagicianSchedule[holiday] = customer; } b.push_back(readinmagician); magicians.setMagician(b); readinmagician.MagicianSchedule.clear(); } // Reads in waitlist. fin >> numWaits; logfile << "\tThe following customers are read in to the waiting list:" << endl; logfile << endl; for (int i = 0; i < numWaits; i++) { fin >> readinwaitlist.custName; fin >> readinwaitlist.holidayName; logfile << "\t\t" << readinwaitlist.custName << " on " << readinwaitlist.holidayName << "." << endl; logfile << endl; c.push_back(readinwaitlist); waitlist.setWaitList(c); } } for (int i = 0; i < 80; i++) { logfile << "-"; } logfile << endl; fin.clear(); fin.close(); } // Done and Error'd. void Database::ScheduleAppt(Magician &magicians, Holiday &holidays, Waitlist &waitlist, ofstream &logfile) { string tempCust; string tempHol; list ::iterator Hol_Itr; list ::iterator Mag_Itr; map ::iterator Sch_Itr; list a = holidays.getHoliday(); list b = magicians.getMagician(); list c = waitlist.getWaitList(); WaitingStruct temp; cout << "Please enter a customer's name: " ; cin >> tempCust; cout << endl; logfile << "The user enters customer " << tempCust << " as a customer who wants to schedule an appointment." << endl; logfile << endl; cout << "Please enter the holiday customer wants a magician for: "; cin >> tempHol; logfile << "The user enters holiday " << tempHol << " as the holiday to be scheduled for." << endl; logfile << endl; system("cls"); // Breaks when at desired holiday. for (Hol_Itr = a.begin(); Hol_Itr != a.end(); Hol_Itr++) { if (Hol_Itr->holidayName == tempHol) break; } // If holiday doesn't exist. if (Hol_Itr == a.end()) { cout << "Error: You have entered a holiday which does not exist." << endl; cout << endl; logfile << "\tError: The user has entered a holiday which does not exist." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { // Searches for open magician. for (Mag_Itr = b.begin(); Mag_Itr != b.end(); Mag_Itr++) { Sch_Itr = Mag_Itr-> MagicianSchedule.find(tempHol); if (Sch_Itr == Mag_Itr-> MagicianSchedule.end()) { Hol_Itr->HolidaySchedule[tempCust] = Mag_Itr->magicianName; Mag_Itr->MagicianSchedule[tempHol] = tempCust; cout << Mag_Itr->magicianName << " has been scheduled to perform for " << tempCust << " on " << tempHol << "." << endl; cout << endl; logfile << "\t" << Mag_Itr->magicianName << " has been scheduled to perform for " << tempCust << " on " << tempHol << "." << endl; logfile << endl; holidays.setHoliday(a); magicians.setMagician(b); cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); break; } } // All magicians busy. if (Mag_Itr == b.end()) { temp.custName = tempCust; temp.holidayName = tempHol; c.push_back(temp); cout << "Currently, no magicians are available to perform on " << tempHol << "." << endl; cout << endl; cout << tempCust << " has been added to the waiting list for a magician on " << tempHol << "." << endl; cout << endl; logfile << "\tCurrently, no magicians are available to perform on " << tempHol << "." << endl; logfile << endl; logfile << "\t" << tempCust << " has been added to the waiting list for a magician on " << tempHol << "." << endl; logfile << endl; waitlist.setWaitList(c); cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } } } // Done and Error'd. void Database::CancelAppt(Magician &magicians, Holiday &holidays, Waitlist &waitlist, ofstream &logfile) { string tempCust; string tempHol; list a = holidays.getHoliday(); list b = magicians.getMagician(); list c = waitlist.getWaitList(); list ::iterator Hol_Itr; list ::iterator Mag_Itr; map::iterator HolSch_Itr; map::iterator MagSch_Itr; list ::iterator Wai_Itr; bool scheduled = false; cout << "Please enter the name of the customer who would like to cancel: "; cin >> tempCust; logfile << "The user enters customer " << tempCust << " as the customer who wants to cancel an appointment." << endl; logfile << endl; cout << endl; cout << "What holiday is " << tempCust << " canceling for: "; cin >> tempHol; logfile << "The user enters holiday " << tempHol << " as the holiday to be cancelled for." << endl; logfile << endl; system("cls"); for (Hol_Itr = a.begin(); Hol_Itr != a.end(); Hol_Itr++) // Iterates through holidays. { if (Hol_Itr->holidayName == tempHol) // If finds desired holiday. { HolSch_Itr = Hol_Itr->HolidaySchedule.find(tempCust); // Find customer assigned to holiday... if (HolSch_Itr == Hol_Itr->HolidaySchedule.end()) // If reaches end without finding customer. { cout << "Error: You have entered a customer who is not currently scheduled" << endl; cout << "for that holiday." << endl; cout << endl; logfile << "\tError: The user has entered a customer who is not currently scheduled for that holiday." << endl; logfile << endl; cout << "Please press any key to check if customer is on waitlist or otherwise to exit..." << endl; logfile << "The user presses any key to check if customer is on waitlist or otherwise to exit." << endl; logfile << endl; getch(); system("cls"); break; } else { Hol_Itr->HolidaySchedule.erase(HolSch_Itr); scheduled = true; // Customer is schedule for an appointment, not waitlist. } for (Mag_Itr = b.begin(); Mag_Itr != b.end(); Mag_Itr++) // Iterates through magicians. { MagSch_Itr = Mag_Itr->MagicianSchedule.find(tempHol); // Finds magician for specified holiday. if (MagSch_Itr->first == tempHol && MagSch_Itr->second == tempCust) { // Cancels appointment from holiday/magician. Mag_Itr->MagicianSchedule.erase(MagSch_Itr); holidays.setHoliday(a); magicians.setMagician(b); cout << tempCust << "'s appointment for " << tempHol << " has been cancelled." << endl; cout << endl; logfile << "\t" << tempCust << "'s appointment for " << tempHol << " has been cancelled." << endl; logfile << endl; cout << "Please press any key to check for changes to waitlist..." << endl; logfile << "The user presses any key to check for changes to the waitlist." << endl; logfile << endl; getch(); system("cls"); break; } } break; } } if (Hol_Itr == a.end()) // If reaches end without finding holiday. { cout << "Error: You have entered a holiday which does not exist." << endl; cout << endl; logfile << "\tError: The user has entered a holiday which does not exist." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } if (scheduled) // Move from waitlist to appointment. { for (Wai_Itr = c.begin(); Wai_Itr != c.end(); Wai_Itr++) { if (Wai_Itr->holidayName == Hol_Itr->holidayName) { Hol_Itr->HolidaySchedule[Wai_Itr->custName] = Mag_Itr->magicianName; Mag_Itr->MagicianSchedule[tempHol] = Wai_Itr->custName; cout << Wai_Itr->custName << " has been removed from the waiting list." << endl; cout << endl; cout << Wai_Itr->custName << " has been scheduled for an appointment on "<< tempHol << " with " << Mag_Itr->magicianName << "." << endl; logfile << "\t" << Wai_Itr->custName << " has been removed from the waiting list." << endl; logfile << endl; logfile << "\t" << Wai_Itr->custName << " has been scheduled for an appointment on "<< tempHol << " with " << Mag_Itr->magicianName << "." << endl; logfile << endl; c.erase(Wai_Itr); holidays.setHoliday(a); magicians.setMagician(b); waitlist.setWaitList(c); cout << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); return; } } } else { for (Wai_Itr = c.begin(); Wai_Itr != c.end(); Wai_Itr++) { if (Wai_Itr->custName == tempCust && Wai_Itr->holidayName == tempHol) { cout << tempCust << " has been removed from the waiting list for " << tempHol << "." << endl; cout << endl; logfile << "\t" << tempCust << " has been removed from the waiting list for " << tempHol << "." << endl; logfile << endl; c.erase(Wai_Itr); holidays.setHoliday(a); magicians.setMagician(b); waitlist.setWaitList(c); cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); return; } } } } // Done and Error'd. void Database::NewMagician(Magician &magicians, Holiday &holidays, Waitlist &waitlist, ofstream &logfile) { list a = holidays.getHoliday(); list b = magicians.getMagician(); list c = waitlist.getWaitList(); list ::iterator Hol_Itr; list ::iterator Mag_Itr; map::iterator Sch_Itr; list ::iterator Wai_Itr; MagicianStruct newMagician; cout << "Please enter the name of the newly acquired magician: "; cin >> newMagician.magicianName; logfile << "The user inputs " << newMagician.magicianName << " as the newly hired magician." << endl; logfile << endl; system("cls"); b.push_back(newMagician); magicians.setMagician(b); cout << newMagician.magicianName << " has been added to the magician list." << endl; cout << endl; logfile << "\t" << newMagician.magicianName << " has been added to the magician list." << endl; logfile << endl; cout << "Press any key to redistribute waitlist..." << endl; logfile << "The user presses any key to redistribute waitlist." << endl; logfile << endl; getch(); system("cls"); Mag_Itr = --b.end(); if (c.empty()) { cout << "There are no available appointments for the magician, at this time." << endl; cout << endl; cout << "He will remain on the magician list." << endl; cout << endl; logfile << "\tThere are no available appointments for the magician, at this time." << endl; logfile << endl; logfile << "\tThe magician will remain on the magician list." << endl; logfile << endl; } else { for (Wai_Itr = c.begin(); Wai_Itr != c.end();) { if (Mag_Itr->MagicianSchedule.find(Wai_Itr->holidayName) == Mag_Itr->MagicianSchedule.end()) { for (Hol_Itr = a.begin(); Hol_Itr != a.end(); Hol_Itr++) { if (Hol_Itr->holidayName == Wai_Itr->holidayName) { break; } } Hol_Itr->HolidaySchedule[Wai_Itr->custName] = Mag_Itr->magicianName; Mag_Itr->MagicianSchedule[Wai_Itr->holidayName] = Wai_Itr->custName; cout << Wai_Itr->custName << " has been removed from the waitlist and scheduled for" << endl; cout << "an appointment with " << Mag_Itr->magicianName << " on " << Wai_Itr->holidayName << "." << endl; cout << endl; logfile << "\t" << Wai_Itr->custName << " has been removed from the waitlist and scheduled for an appointment with " << Mag_Itr->magicianName << " on " << Wai_Itr->holidayName << "." << endl; logfile << endl; Wai_Itr = c.erase(Wai_Itr); holidays.setHoliday(a); magicians.setMagician(b); waitlist.setWaitList(c); } else // Done so erase works. { Wai_Itr++; } } } } // Done and Error'd. void Database::DelMagician(Magician &magicians, Holiday &holidays, Waitlist &waitlist, ofstream &logfile) { string tempHol; string tempCust; string QuitMag; list a = holidays.getHoliday(); list b = magicians.getMagician(); list c = waitlist.getWaitList(); list ::iterator Hol_Itr; list ::iterator Mag_Itr; map::iterator Sch_Itr; map::iterator MagSch_Itr; WaitingStruct temp; cout << "Please enter the name of the magician who is quitting: "; cin >> QuitMag; logfile << "The user enters magician " << QuitMag << " as the magician who is quitting." << endl; logfile << endl; system("cls"); // Interates through magician until finds input magician. for (Mag_Itr = b.begin(); Mag_Itr != b.end(); Mag_Itr++) { if (Mag_Itr->magicianName == QuitMag) { break; } } if (Mag_Itr == b.end()) { cout << "Error: You have entered a magician who does not work for the agency." << endl; cout << endl; logfile << "\tError: The user has entered a magician who does not work for the agency." << endl; logfile << endl; } else { b.erase(Mag_Itr); cout << QuitMag << " has left the agency." << endl; cout << endl;\ logfile << "\t" << QuitMag << " has left the agency." << endl; logfile << endl; cout << "Press any key to resign appointments..." << endl; logfile << "The user presses any key to resign appointments." << endl; logfile << endl; getch(); system("cls"); for (Hol_Itr = a.begin(); Hol_Itr != a.end(); Hol_Itr++) // Iterates through holidays. { for (Sch_Itr = Hol_Itr->HolidaySchedule.begin(); Sch_Itr != Hol_Itr->HolidaySchedule.end(); Sch_Itr++) { if (Sch_Itr->second == QuitMag) // If holiday assigned to quitting magician... { tempHol = Hol_Itr->holidayName; tempCust = Sch_Itr->first; for (Mag_Itr = b.begin(); Mag_Itr != b.end(); Mag_Itr++) { MagSch_Itr = Mag_Itr->MagicianSchedule.find(tempHol); // ...find that holiday in magician list. if (MagSch_Itr == Mag_Itr->MagicianSchedule.end()) { // Erases old spot and assigns new spot. Hol_Itr->HolidaySchedule.erase(Sch_Itr); Hol_Itr->HolidaySchedule[tempCust] = Mag_Itr->magicianName; Mag_Itr->MagicianSchedule[tempHol] = tempCust; cout << tempCust << " has been rescheduled for " << tempHol << " with " << Mag_Itr->magicianName << "." << endl; cout << endl; logfile << "\t" << tempCust << " has been rescheduled for " << tempHol << " with " << Mag_Itr->magicianName << "." << endl; logfile << endl; holidays.setHoliday(a); magicians.setMagician(b); break; } } if (Mag_Itr == b.end()) // If no available magicians. { Hol_Itr->HolidaySchedule.erase(Sch_Itr); temp.custName = tempCust; temp.holidayName = tempHol; c.push_front(temp); cout << tempCust << " has been put to the front of the waiting list for " << tempHol << "." << endl; cout << endl; logfile << "\t" << tempCust << " has been put to the front of the waiting list for " << tempHol << "." << endl; logfile << endl; holidays.setHoliday(a); magicians.setMagician(b); waitlist.setWaitList(c); } break; } } } if (Hol_Itr == a.end()) { holidays.setHoliday(a); magicians.setMagician(b); waitlist.setWaitList(c); } } } // Done and Error'd. void Database::CheckStatus(list holidays, list magicians, list waitinglist, ofstream &logfile) { string input; list ::iterator Hol_Itr; list ::iterator Mag_Itr; map ::iterator Sch_Itr; list ::iterator Wai_Itr; int choice; logfile << "The following menu is displayed:" << endl; logfile << endl; logfile << "\tPlease select which item you would like to view the status of." << endl; logfile << endl; logfile << "\t1: Magician" << endl; logfile << "\t2: Holiday" << endl; logfile << "\t3: Waiting list" << endl; logfile << endl; logfile << "\tEnter choice: " << endl; logfile << endl; cout << "Please select which item you would like to view the status of." << endl; cout << endl; cout << "1: Magician" << endl; cout << "2: Holiday" << endl; cout << "3: Waiting list" << endl; cout << endl; cout << "Enter choice: "; cin >> choice; system("cls"); switch (choice) { case 1: logfile << "The user enters 1." << endl; logfile << endl; cout << "Please enter magician's name: "; cin >> input; logfile << "\tThe user enters magician " << input << " as the magician whose status to view." << endl; logfile << endl; system("cls"); // Searches for magician. for (Mag_Itr = magicians.begin(); Mag_Itr != magicians.end(); Mag_Itr++) { if (Mag_Itr-> magicianName == input) { break; } } // Magician doesn't exist. if (Mag_Itr == magicians.end()) { cout << "Error: You have entered a magician who does not work for the agency." << endl; cout << endl; logfile << "\t\tError: The user has entered a magician who does not work for the agency." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { if (Mag_Itr->MagicianSchedule.empty()) { cout << input << " currently has no parties scheduled." << endl; cout << endl; logfile << "\t\t" << input << " currently has no parties scheduled." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { cout << "Here is the schedule for " << input << "." << endl; cout << endl; cout << left << setw(16) << " Holiday"; cout << left << "Customer" << endl; cout << " "; for (int i = 0; i < 40; i++) { cout << "-"; } cout << endl; for (Sch_Itr = Mag_Itr->MagicianSchedule.begin(); Sch_Itr != Mag_Itr->MagicianSchedule.end(); Sch_Itr++) { cout << left << " " << setw(14) << Sch_Itr->first; cout << left << Sch_Itr->second << endl; } cout << endl; logfile << "\t\tHere is the schedule for " << input << ":" << endl; logfile << endl; logfile << "\t\t" << left << setw(16) << " Holiday"; logfile << left << "Customer" << endl; logfile << "\t\t "; for (int i = 0; i < 40; i++) { logfile << "-"; } logfile << endl; for (Sch_Itr = Mag_Itr->MagicianSchedule.begin(); Sch_Itr != Mag_Itr->MagicianSchedule.end(); Sch_Itr++) { logfile << "\t\t "; logfile << left << " " << setw(14) << Sch_Itr->first; logfile << left << Sch_Itr->second << endl; } logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } } break; case 2: logfile << "The user enters 2." << endl; logfile << endl; cout << "Please enter a holiday: "; cin >> input; logfile << "\tThe user enters holiday " << input << " as the holiday whose status to view." << endl; logfile << endl; system("cls"); // Searches for holiday. for (Hol_Itr = holidays.begin(); Hol_Itr != holidays.end(); Hol_Itr++) { if (Hol_Itr-> holidayName == input) { break; } } // Holiday doesn't exist. if (Hol_Itr == holidays.end()) { cout << "Error: You have entered a holiday that does not exist." << endl; cout << endl; logfile << "\t\tError: The user has entered a holiday that does not exist." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { if (Hol_Itr-> HolidaySchedule.empty()) { cout << "There are currently no bookings for " << input << "." << endl; cout << endl; logfile << "\t\tThere are currently no bookings for " << input << "." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { cout << "Here is the schedule for " << input << "." << endl; cout << endl; cout << left << setw(16) << " Customer"; cout << left << "Magician" << endl; cout << " "; for (int i = 0; i < 40; i++) { cout << "-"; } cout << endl; for (Sch_Itr = Hol_Itr->HolidaySchedule.begin(); Sch_Itr != Hol_Itr->HolidaySchedule.end(); Sch_Itr++) { cout << left << " " << setw(14) << Sch_Itr->first; cout << left << Sch_Itr->second << endl; } cout << endl; logfile << "\t\tHere is the schedule for " << input << ":" << endl; logfile << endl; logfile << "\t\t" << left << setw(16) << " Customer"; logfile << left << "Magician" << endl; logfile << "\t\t "; for (int i = 0; i < 40; i++) { logfile << "-"; } logfile << endl; for (Sch_Itr = Hol_Itr->HolidaySchedule.begin(); Sch_Itr != Hol_Itr->HolidaySchedule.end(); Sch_Itr++) { logfile << "\t\t "; logfile << left << " " << setw(14) << Sch_Itr->first; logfile << left << Sch_Itr->second << endl; } logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } } break; case 3: logfile << "The user enters 3." << endl; logfile << endl; if (waitinglist.empty()) // If empty { cout << "The waiting list is empty." << endl; cout << endl; logfile << "\tThe waiting list is empty." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } else { logfile << "\tThe waitlist is as follows:" << endl; logfile << endl; logfile << "\t" << left << setw(16) << " Customer"; logfile << left << "Holiday" << endl; logfile << "\t "; for (int i = 0; i < 40; i++) { logfile << "-"; } logfile << endl; for (Wai_Itr = waitinglist.begin(); Wai_Itr != waitinglist.end(); Wai_Itr++) { logfile << "\t" << left << " " << setw(14) << Wai_Itr->custName; logfile << left << Wai_Itr->holidayName << endl; } logfile << endl; cout << "The waitlist is as follows:" << endl; cout << endl; cout << left << setw(16) << " Customer"; cout << left << "Holiday" << endl; cout << " "; for (int i = 0; i < 40; i++) { cout << "-"; } cout << endl; for (Wai_Itr = waitinglist.begin(); Wai_Itr != waitinglist.end(); Wai_Itr++) { cout << left << " " << setw(14) << Wai_Itr->custName; cout << left << Wai_Itr->holidayName << endl; } cout << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } break; default: cout << "This is not a valid option..." << endl; cout << endl; logfile << "The user has selected an invalid option." << endl; logfile << endl; cout << "Please press any key to return to main menu." << endl; logfile << "The user presses any key to return to main menu." << endl; logfile << endl; getch(); } } // Done and Error'd. void Database::EndFile(list holidays, list magicians, list waitinglist, ofstream &logfile) { ofstream fout; list ::iterator Hol_Itr; list ::iterator Mag_Itr; list ::iterator Wai_Itr; map::iterator Sch_Itr; fout.open("schedule.txt"); logfile << "As the user exits, information about the current schedule is saved to schedule.txt" << endl; logfile << endl; logfile << "\tThe following information is saved for each holiday:" << endl; logfile << endl; // Writes holidays. fout << holidays.size() << endl; for (Hol_Itr = holidays.begin(); Hol_Itr != holidays.end(); Hol_Itr++) { fout << Hol_Itr->holidayName << endl; fout << Hol_Itr->HolidaySchedule.size() << endl; logfile << "\t\tFor " << Hol_Itr->holidayName << ":" << endl; logfile << endl; for (Sch_Itr = Hol_Itr->HolidaySchedule.begin(); Sch_Itr != Hol_Itr->HolidaySchedule.end(); Sch_Itr++) { fout << Sch_Itr->first << " " << Sch_Itr->second << endl; logfile << "\t\t\t" << Sch_Itr->first << " " << Sch_Itr->second << endl; logfile << endl; } } logfile << "\tThe following information is saved for each magician:" << endl; logfile << endl; // Writes magicians. fout << magicians.size() << endl; for (Mag_Itr = magicians.begin(); Mag_Itr != magicians.end(); Mag_Itr++) { fout << Mag_Itr->magicianName << endl; fout << Mag_Itr->MagicianSchedule.size() << endl; logfile << "\t\tFor " << Mag_Itr->magicianName << ":" << endl; logfile << endl; for (Sch_Itr = Mag_Itr->MagicianSchedule.begin(); Sch_Itr != Mag_Itr->MagicianSchedule.end(); Sch_Itr++) { fout << Sch_Itr-> first << " " << Sch_Itr->second <first << " " << Sch_Itr->second << endl; logfile << endl; } } logfile << "\tThe following information is saved for the waitlist:" << endl; logfile << endl; // Writes waitlist. fout << waitinglist.size() << endl; for (Wai_Itr = waitinglist.begin(); Wai_Itr != waitinglist.end(); Wai_Itr++) { fout << Wai_Itr->custName << " " << Wai_Itr->holidayName << endl; logfile << "\t\t" << Wai_Itr->custName << " " << Wai_Itr->holidayName << endl; logfile << endl; } } // Done and Error'd.