//////////////////////////////////////// // This is the extended SICK catering // program. //////////////////////////////////////// // Standard included things #include #include #include #include using namespace std; //////////////////////////////////////// // Function prototypes void print_menu(); void load_file(vector &, vector &, vector &); void display_lists(vector, vector, vector); void clear_lists(vector&, vector&, vector&); void total_food_items(vector); void print_guest_list(vector, vector); int count_guests(vector); //////////////////////////////////////// // Main function // //Repeatedly takes input from the keyboard and calls different //functions based on what is entered. int main(){ vector table_number; vector food_items; vector names; bool done = false; char choice; int number_of_guests = 0; //Loop forever, or until done gets changed while (!done){ // Print the menu for the user print_menu(); cin >> choice; switch(choice){ case 'L': case 'l': load_file(table_number, food_items, names); break; case 'D': case 'd': display_lists(table_number, food_items, names); break; case 'C': case 'c': clear_lists(table_number, food_items, names); break; case 'F': case 'f': total_food_items(food_items); break; case 'G': case 'g': print_guest_list(table_number, names); break; case 'N': case 'n': number_of_guests = count_guests(names); cout << "There are " << number_of_guests << " guests attending." << endl; break; case 'X': case 'x': done = true; cout << "Goodbye" << endl; break; default: cout << "Bad command option." << endl; } } } //////////////////////////////////////// // print_menu displays what options are // available to the user when called void print_menu(){ cout << endl << endl; cout << "Menu options:" << endl; cout << setw(30) << "Load a file: L" << endl; cout << setw(30) << "Display current lists: D" << endl; cout << setw(30) << "Clear all lists: C" << endl; cout << setw(30) << "Show food item count: F" << endl; cout << setw(30) << "Print guest list: G" << endl; cout << setw(30) << "Show number of guests: N" << endl; cout << setw(30) << "Exit: X" << endl << endl; cout << "Your choice: "; } //////////////////////////////////////// // load file askes the user for the name of a file. It then opens the // file and reads the contents into the three vectors, which are // passed as reference variables. This should replace any prior // contents of the vectors. If the file is not found, it prints a // message saying so and that the file will not be loaded. void load_file(vector & tables, vector & foods, vector & guest_names){ ifstream infile; string filename; int table_num; string food_item, guest; cout << "Enter filename to load: "; cin >> filename; infile.open(filename.c_str()); if (!infile){ cout << "File not found. No list will be loaded" << endl; return; } clear_lists(tables,foods,guest_names); infile >> table_num >> food_item; getline(infile, guest); while (infile){ tables.push_back(table_num); foods.push_back(food_item); guest_names.push_back(guest); infile >> table_num >> food_item; getline(infile, guest); } return; } //////////////////////////////////////// // display_lists simply prints out the contents of the vectors // neatly. This allows us to make sure that the vectors were loaded // correctly and to see what is in them. void display_lists(vector tables, vector foods, vector guests){ cout << setw(10) << "Table:" << setw(10) << "Food:" << setw(30) << "Name:" << endl; for (int i = 0; i & tables, vector & foods, vector & guests){ tables.clear(); foods.clear(); guests.clear(); return; } //////////////////////////////////////// // total_food_items takes the vector of foods and counts up how many // of each dish have been ordered. It then outputs the count. If there // is a bad food item, it outputs what bad item it is, but keeps // counting. void total_food_items(vector foods){ int beef = 0, chicken = 0, veggie = 0, fish = 0; cout << endl; for (int i = 0; i < foods.size();i++){ switch(foods[i].at(0)){ // yummy beef case 'B': case 'b': beef++; break; // cheaper chicken case 'c': case 'C': chicken++; break; // healthy fish case 'f': case 'F': fish++; break; // super healthy veggies case 'v': case 'V': veggie++; break; default: cout << "Bad food item in data file: " << foods[i] << endl; } } cout << endl; cout << "Total food items:" << endl; cout << setw(15) << "Beef: " << setw(5) << beef << endl; cout << setw(15) << "Chicken: " << setw(5) << chicken << endl; cout << setw(15) << "Fish: " << setw(5) << fish << endl; cout << setw(15) << "Veggie: " << setw(5) << veggie << endl; return; } //////////////////////////////////////// // print_guest_list prints out the table numbers and names of the // guests in a neat two column format. void print_guest_list(vector tables, vector names){ cout << setw(10) << "Table: " << setw(50) << "Name:" << endl; for (int i = 0; i < tables.size(); i++){ cout << setw(10) << tables[i] << setw(50) << names[i] << endl; } cout << endl; return; } //////////////////////////////////////// // count_guests returns the number of guests who will be attending the // wedding. int count_guests(vector guests){ return guests.size(); }