Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Lab 1
- CS2
- Updated by: Tommy Weber (5 points) - fixed
- Date: 1/18/2019 (5 points) - fixed
- Breakfast billing system for a restaurant.
- This program allows restaurant customers to select breakfast items and prints the bill.
- Problem Requirements
- - Write a C++ program to help a local restaurant automate its breakfast billing system. The program should do the following at a minimum.
- - Program should read the menu data from file menu.txt, sample is provided to you.
- - Show customer the different breakfast items offered by the restaurant.
- - Allow customer to select more than one item from the menu.
- - Do not allow customer to select the same item more than once.
- - When done selecting items, prompt user to enter filename and save the receipt in the output file as shown in the given guest1.check sample file.
- - Bonus 10 points. Make the program run continuously, until the user wants to quit.
- Follow best programming practices:
- - Write adequate comments. Comments can help you plan for the solution and think through the problem.
- - Refrain from using global variables; constants are okay.
- - Use adequate indentation and whitespaces to cleanly format your code.
- Submission:
- If your program doesn’t compile, you’ll get a zero for this lab.
- Add all the source file(s) *.cpp, *.h, etc., sample input and output files into the repository
- $ git status
- $ git add … - add each file that was new or modified that is part of the lab
- $ git commit -m “Final Submission”
- $ git push
- NOTE: Do not modify this folder contents after the due date as it may be considered late submission!
- ===================================================================================
- */
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- using namespace std;
- // max no. of menu items that can be stored by the program
- const int NO_OF_ITEMS = 8;
- // data structure to hold each menu item info
- struct menuItemType
- {
- string itemName;
- double itemPrice;
- };
- // initialize menu list with some default values
- void initMenuList(menuItemType menuList[], int menuListSize);
- // function that reads menu data into menuList array
- void readMenuData(ifstream& fin, menuItemType menuList[], int menuListSize);
- // function that displays the menu
- void showMenu(menuItemType menuList[], int menuListSize);
- // function to print check after menu items are selected
- void printCheck(menuItemType menuList[], int menuListSize,
- int selectedList[], int selectedListLength);
- // function to select items from the menu list
- void makeSelection(menuItemType menuList[], int menuListSize,
- int selectedList[], int& selectedListLength);
- // function that returns true if the itemNo is in the selectedList otherwise false.
- // this function avoids user repeating the menu item
- bool isItemSelected(int selectedList[], int selectedListLength, int itemNo);
- int main()
- {
- menuItemType menuList[NO_OF_ITEMS];
- int choiceList[NO_OF_ITEMS]; // array to keep track of choices based on item number
- int choiceListLength; // variable to keep track of no. of choices
- ifstream fin;
- cout << fixed << showpoint << setprecision(2);
- // open menu.txt file to read menu data from
- string menuFileName = "menu.txt";
- fin.open(menuFileName);
- if (!fin)
- {
- cout << "Input file " << menuFileName << " does not exist. Program Terminates!"
- << endl;
- cout << "Hit enter to terminate the program!";
- cin.get();
- return 1;
- }
- initMenuList(menuList, NO_OF_ITEMS);
- // FIXME3 – (5 points) - fixed
- // Call readMenuData function passing proper arguments
- readMenuData(fin, menuList, NO_OF_ITEMS);
- fin.close(); //close input file
- showMenu(menuList, NO_OF_ITEMS);
- makeSelection(menuList, NO_OF_ITEMS, choiceList, choiceListLength);
- printCheck(menuList, NO_OF_ITEMS, choiceList, choiceListLength);
- // pause the program until a key is entered
- cin.get();
- cin.get();
- return 0;
- }
- void initMenuList(menuItemType menuList[], int menuListSize)
- {
- int itemNameCount = 0, itemPriceCount = 1; // Will help assign items in menuList to both .itemName & .itemPrice
- const int MAX = (menuListSize*2);
- string fullMenuList[MAX] = {"Plain Egg", "0", "Bacon and Egg", "0", "Muffin", "0", "French Toast", "0",
- "Fruit Basket", "0", "Cereal", "0", "Coffee", "0", "Tea", "0"};
- // Assigns values to items in class.
- for (int i = 0; i < menuListSize; ++i)
- {
- // FIXME4 (5 points) - fixed
- // Initialize each menu item's name to A Tasty Item (DONE)
- // Initialize each menu item's price to 0; (DONE)
- menuList[i].itemName = fullMenuList[itemNameCount];
- menuList[i].itemPrice = stod( fullMenuList[itemPriceCount] );
- //cout << "Debug #38571: " << menuList[i].itemName << " " << menuList[i].itemPrice << "\n";
- itemNameCount += 2;
- itemPriceCount += 2;
- }
- }
- void readMenuData(ifstream& fin, menuItemType menuList[], int menuListSize)
- {
- char ch;
- for (int i = 0; i < menuListSize; i++)
- {
- // FIXME5 (10 points) - WIP
- // 1. Read each item name into itemName field of menuList array
- // 2. Read each item price into itemPrice field of menuList array
- //cout << menuList[i].itemName << "\n";
- }
- }
- void showMenu(menuItemType menuList[], int menuListSize)
- {
- cout << "Welcome to Papi Joey's Kitchen" << endl;
- cout << "----Today's Menu----" << endl;
- for (int i = 0; i < menuListSize; i++)
- {
- cout << i + 1 << ": " << left << setw(15) << menuList[i].itemName
- << right << " $" << menuList[i].itemPrice << endl;
- }
- cout << endl;
- }
- void printCheck(menuItemType menuList[], int menuListSize,
- int selectedList[], int selectedListLength)
- {
- int i;
- double salesTax;
- double amountDue = 0;
- cout << " Papi Joey's Kitchen" << endl;
- cout << " Guest Check " << endl;
- cout << setw(25) << setfill('=') << endl;
- cout << setfill(' ') << endl;
- for (i = 0; i < selectedListLength; i++)
- {
- cout << left << setw(15) << menuList[selectedList[i]].itemName
- << right << " $" << setw(4) << menuList[selectedList[i]].itemPrice << endl;
- amountDue += menuList[selectedList[i]].itemPrice;
- }
- cout << endl;
- salesTax = amountDue * .07;
- cout << left << setw(15) << "Tax " << right << " $"
- << salesTax << endl;
- amountDue = amountDue + salesTax;
- cout << left << setw(15) << "Amount Due " << right
- << " $" << amountDue << endl << endl;
- cout << setw(25) << setfill('=') << ' ' << endl;
- cout << setfill(' ') << endl;
- cout << " Thank you! " << endl;
- // FIXME6 (10 points)
- // 1. Prompt user to enter output filename to write receipt data.
- // 2. Create the file and write the check info (as you see on the common output) into the file.
- // 3. Provide feedback to the user, once done.
- // 4. Close the file.
- }
- void makeSelection(menuItemType menuList[], int menuListSize, int selectedList[],
- int& selectedListLength)
- {
- int selectionNo = 0;
- int itemNo;
- char response;
- selectedListLength = 0;
- cout << "You can make up to " << menuListSize
- << " single order selections" << endl;
- cout << "Do you want to make selection Y/y (Yes), N/n (No): ";
- cin >> response;
- cout << endl;
- while ((response == 'Y' || response == 'y') &&
- selectedListLength < menuListSize)
- {
- cout << "Enter item number: ";
- cin >> itemNo;
- cout << endl;
- if (!isItemSelected(selectedList, selectedListLength, itemNo))
- selectedList[selectedListLength++] = itemNo - 1;
- else
- cout << "Item already selected" << endl;
- cout << "Select another item Y/y (Yes), N/n (No): ";
- cin >> response;
- cout << endl;
- }
- }
- bool isItemSelected(int selectedList[], int selectedListLength, int itemNo)
- {
- bool found = false;
- /*
- FIXME7 (10 points)
- Algorithm steps:
- 1. Go through each item in selectedList and check if itemNo is in there.
- 2. If it is, return true, otherwise false
- */
- return found;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement