#include #include #include #include "guestLinkedListClass.h" using namespace std; void OpenFile(char fileName[], fstream & fileStream, int iosInOut); // prototype for OpenFile int main() { fstream inFile; // inFile name fstream outFile; // outFile name DinnerGuestList dinnerObject; //object of DinnerGuestList DinnerGuest updateList[MAX_UPDATES] = {{"Beachum", STK},{"Fred",CHICK},{"Iguban",STK}}; // array of names to update char names[MAX_NAME]; // char array for names char meal; // char for meal type MealType mealTyp; // MealType to store meal type OpenFile("guestList.txt", inFile, ios::in); OpenFile("guestListoutput.out", outFile, ios::out); inFile >> names; // name priming read inFile >> meal; // meal priming read while (inFile) //while file has data { switch (meal) // check for meal type { case 'C': mealTyp = CHICK; break; case 'V': mealTyp = VEG; break; case 'S': mealTyp = STK; break; default: cout << "Incorrect Meal Type\n"; }//switch dinnerObject.InsertSorted(names, mealTyp); // call InsertSorted to store info inFile >> names; // next read inFile >> meal; // next read } //while dinnerObject.PrintGuestList(outFile); // Prints guest list dinnerObject.PrintMeals(outFile); // Prints meals for (int i = 0; i < MAX_UPDATES; i++) // transverses through updateList { if( dinnerObject.UpdateGuest(updateList[i].guestName, updateList[i].mealTyp) ) // calls UpdateGuest and checks bool value { outFile << updateList[i].guestName << "'s meal was changed to " << MEAL_NAMES[updateList[i].mealTyp] << "\n"; } else { outFile << updateList[i].guestName << " not found on guest list\n"; } } // for outFile << "\n"; // new line dinnerObject.PrintGuestList(outFile); // Prints guest list dinnerObject.PrintMeals(outFile); // Prints meals for (int i = 0; i < MAX_DELETES; i++) // transverses through DELETE_NAMES { if (dinnerObject.IsPresent(DELETE_NAMES[i])) //calls IsPresent and checks bool value { dinnerObject.DeleteGuest(DELETE_NAMES[i]); // calls DeleteGuest to delete name outFile << DELETE_NAMES[i] << " deleted from the list\n\n"; } else { outFile << DELETE_NAMES[i] << " could not be deleted from the list\n\n"; } } // for outFile << "\n"; // new line dinnerObject.PrintGuestList(outFile); // Prints guest list dinnerObject.PrintMeals(outFile); // Prints meals inFile.close(); // close input file outFile.close(); // close output file return 0; } // main //************************************************************ // OpenFile()- Takes filename, file stream, openmode // and opens the file and checks for errors // Returns: NA //************************************************************* void OpenFile(char fileName[], // filename to open fstream & fileStream, // file stream int iosInOut) // openmode { fileStream.open(fileName, (std::_Ios_Openmode)iosInOut); // opens file if(!fileStream) // checks if file opened { cerr << "File did not open\nHit enter to exit"; cin.get(); exit(1); } } // OpenFile