Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.07 KB | None | 0 0
  1. /*
  2.  *  sandwich_template.cpp
  3.  *
  4.  *
  5.  *  Created by Eric Weesner on 6/27/11.
  6.  *  Copyright 2011 Butte College. All rights reserved.
  7.  *
  8.  */
  9.  
  10. #include <iostream>
  11. #include <cstdlib>
  12. #include <fstream>
  13. #include "CinReader.h"
  14.  
  15. using namespace std;
  16.  
  17. CinReader reader;
  18.  
  19. const string BREAD[4] = {"Whole Wheat", "White", "Rye", "French Roll"};
  20. const string MEAT[5] = {"Turkey", "Ham", "Roast Beef", "Pastrami", "Bacon"};
  21. const string CHEESE[3] = {"Cheddar", "Swiss", "Provolone"};
  22. const string VEGGIE[3] = {"Lettuce", "Tomato", "Onion"};
  23. const string CONDIMENT[3] = {"Mayonaise", "Mustard", "Ranch"};
  24.  
  25. struct Sandwich
  26. {
  27.     string bread;
  28.     string meat;
  29.     string cheese;
  30.     string veggie;
  31.     string condiment;
  32. };
  33.  
  34. void intro ();
  35.  
  36. /**     This function displays the ingredients of a sandwich to a
  37.  *      specified output source (i.e. console, file, etc).
  38.  *      @param out the generic output source. The programmer must
  39.  *          specify the source
  40.  *      @param s the user supplied Sandwich
  41.  */
  42. void display(ostream& out, Sandwich s);
  43.  
  44. /**     Prints out a receipt for the customer.
  45.  *      @ param s the user supplied Sandwich
  46.  */
  47. void printReceipt(Sandwich s);
  48.  
  49. void saveSandwich(Sandwich s);
  50.  
  51. /**     Reads in the last sandwich made.
  52.  *      @param fileAccess, the call by reference boolean expression
  53.  *      used to help determine whether a file was opened successfully
  54.  *      for reading.  NOTE TO PROGRAMMER:  This should be set to false
  55.  *      if the file can not be opened.
  56.  *      @return a sandwich of type Sandwich
  57.  */
  58. Sandwich readSandwich(bool& fileAccess);
  59.  
  60. string breadChoice();
  61.  
  62. string meatChoice();
  63.  
  64. string cheeseChoice();
  65.  
  66. string veggieChoice();
  67.  
  68. string condimentChoice();
  69.  
  70.  
  71.  
  72. int main()
  73. {
  74.     Sandwich s;
  75.  
  76.     intro();
  77.     system("cls");
  78.     s.bread = breadChoice();
  79.     system("cls");
  80.     s.meat = meatChoice();
  81.     system("cls");
  82.     s.cheese = cheeseChoice();
  83.     system("cls");
  84.     s.veggie = veggieChoice();
  85.     system("cls");
  86.     s.condiment = condimentChoice();
  87.     system("cls");
  88.     saveSandwich(s);
  89.  
  90.  
  91.     cout << s.bread << s.meat << s.cheese << s.veggie << s.condiment;
  92.     return 0;
  93. }
  94.  
  95. void intro()
  96. {
  97.     char ready;
  98.     //system("clear");
  99.     cout << "HELLO! Welcome to Warren's Sandwich Shop.  My sandwich"<< endl
  100.     << "making ability is very limited.  Therefore, you will only" << endl
  101.     << "be able to order one sandwich.  Your sandwich will may only" << endl
  102.     << "consist of one of each type of the following: " << endl
  103.     << "1. Bread" << endl
  104.     << "2. Meat" << endl
  105.     << "3. Cheese" << endl
  106.     << "4. Vegetable" << endl
  107.     << "5. Condiment" << endl << endl;
  108.     cout << "Are you ready to order (y/n)?  ";
  109.     ready = reader.readChar("YyNn");
  110.     if (ready == 'n' || ready == 'N')
  111.     {
  112.         cout << "\nY'all come back now!" << endl << endl;
  113.         exit(0);
  114.     }
  115.     else
  116.     {
  117.         cout << "\nGreat, let's make a sandwich!" << endl;
  118.         cout << "Press enter to continue.";
  119.         reader.readString();
  120.         cout << endl;
  121.     }
  122. }
  123.  
  124.  
  125. void display(ostream& out, Sandwich s)
  126. {
  127.  
  128. }
  129.  
  130. void printReceipt(Sandwich s)
  131. {
  132.  
  133. }
  134.  
  135. void saveSandwich(Sandwich s)
  136. {
  137.     ofstream outFile("savedSandwich.txt");
  138.     outFile << s.bread <<":"
  139.             << s.meat  <<":"
  140.             << s.cheese <<":"
  141.             << s.veggie <<":"
  142.             << s.condiment
  143.             << endl;
  144. }
  145. /*Sandwich readSandwich(bool& fileAccess)
  146. {
  147.     ifstream inFile("savedSandwich.txt");
  148.     if(!inFile)
  149.     {
  150.         return false;
  151.     }
  152.     else
  153.     {
  154.         //read file!s
  155.     }
  156. }
  157. */
  158.  
  159.  
  160. string breadChoice()
  161. {
  162.     cout << "\nPlease select a number from the following selection\n\n";
  163.     string bread;
  164.         for(int i=0; i<4; i++)
  165.     {
  166.         cout << i+1 << ". " << BREAD[i] << endl;
  167.     }
  168.  
  169.         cout << "\n\nWhat bread would you like? ";
  170.         int c = reader.readInt(1,4);
  171.         return BREAD[c-1];
  172. }
  173. string meatChoice()
  174. {
  175.     cout << "\nPlease select a number from the following selection\n\n";
  176.     string meat;
  177.         for(int i=0; i<5; i++)
  178.     {
  179.         cout << i+1 << ". " << MEAT[i] << endl;
  180.     }
  181.  
  182.         cout << "\n\nWhat Meat would you like? ";
  183.         int c = reader.readInt(1,5);
  184.         return MEAT[c-1];
  185. }
  186. string cheeseChoice()
  187. {
  188.     cout << "\nPlease select a number from the following selection\n\n";
  189.     string cheese;
  190.         for(int i=0; i<3; i++)
  191.     {
  192.         cout << i+1 << ". " << CHEESE[i] << endl;
  193.     }
  194.  
  195.         cout << "\n\nWhat Cheese would you like? ";
  196.         int c = reader.readInt(1,3);
  197.         return CHEESE[c-1];
  198. }
  199. string veggieChoice()
  200. {
  201.     cout << "\nPlease select a number from the following selection\n\n";
  202.     string veggie;
  203.         for(int i=0; i<3; i++)
  204.     {
  205.         cout << i+1 << ". " << VEGGIE[i] << endl;
  206.     }
  207.  
  208.         cout << "\n\nWhat Veggie would you like? ";
  209.         int c = reader.readInt(1,3);
  210.         return VEGGIE[c-1];
  211. }
  212. string condimentChoice()
  213. {
  214.     cout << "\nPlease select a number from the following selection\n\n";
  215.     string condiment;
  216.         for(int i=0; i<3; i++)
  217.     {
  218.         cout << i+1 << ". " << CONDIMENT[i] << endl;
  219.     }
  220.  
  221.         cout << "\n\nWhat Condiment would you like? ";
  222.         int c = reader.readInt(1,3);
  223.         return CONDIMENT[c-1];
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement