Guest User

Untitled

a guest
Jun 30th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.41 KB | None | 0 0
  1.     #include <iostream>
  2.     #include <fstream>
  3.     #include <conio.h>
  4.     #include <string>
  5.     #include <windows.h>
  6.      
  7.     using namespace std;
  8.      
  9.     const int quit = 7;
  10.     const int MAX = 3;
  11.      
  12.     struct tm *Sys_T = NULL;
  13.      
  14.     //set up record structure
  15.     struct coffeerec
  16.     {
  17.             string beans;
  18.             int num_in_stock;
  19.             string date_purchased;
  20.     };
  21.      
  22.     typedef coffeerec coffeeArrayType[3];
  23.     coffeeArrayType coffee;
  24.      
  25.      
  26.     string uname, password;
  27.     char ch;
  28.     int che;
  29.     int in_sys;
  30.     int choice;
  31.     int amount;
  32.     string datebought;
  33.      
  34.      
  35.     void logon();
  36.     void readfile();
  37.     void writefile();
  38.     void managermenu();
  39.     void barristamenu();
  40.     void date();
  41.     void display();
  42.     void processorder();
  43.     void addstock();
  44.     void manager_act_on_choice();
  45.     void barrista_act_on_choice();
  46.      
  47.     // details of the actual array of records
  48.      
  49.     void main()
  50.     {
  51.             date();
  52.             logon();
  53.             if (in_sys == 1)
  54.             {
  55.                     while (choice !=4)
  56.                     {
  57.                             managermenu();
  58.                             manager_act_on_choice();
  59.                     }
  60.      
  61.             }
  62.             else if (in_sys ==2)
  63.             {
  64.                     while (choice !=3)
  65.                     {
  66.                             barristamenu();
  67.                             barrista_act_on_choice();
  68.                     }
  69.             }
  70.      
  71.     }
  72.      
  73.      
  74.     void logon()
  75.     {
  76.            
  77.             cout << "Enter username: " << "\n";
  78.             cin >> uname;
  79.             cout << "Enter Password: " << "\n";
  80.      
  81.             ch = _getch();
  82.             while (ch!= 13) // 13 is the enter key
  83.             {
  84.                    
  85.                     password.push_back(ch);
  86.                     cout << "*";
  87.                     ch=_getch();
  88.             }
  89.            
  90.             if (uname.compare ("manager")==0 && password.compare ("man")==0)
  91.             {
  92.                     cout << " Hello Boss \n";
  93.                     in_sys = 1;
  94.      
  95.      
  96.                    
  97.            
  98.             }
  99.             else if (uname.compare ("barrista")==0 && password.compare ("bar")==0)
  100.             {
  101.                     in_sys = 2;
  102.             }
  103.      
  104.      
  105.      
  106.             else
  107.                     system("pause");
  108.                     cout << "Bah Humbug - Go away";
  109.            
  110.     }
  111.            
  112.      
  113.     void writefile()
  114.     {        ofstream fileout("M:\\coffee.txt",ios::out);
  115.        
  116.     for (int i =0;i<3;i++)
  117. {
  118.         fileout << coffee[i].beans <<"\t" << coffee[i].num_in_stock  << "\t" << coffee[i].date_purchased << "\n";
  119.        
  120. }
  121.  
  122. fileout.close();    
  123.            
  124.     }//end method
  125.      
  126.      
  127.     void addstock()
  128.     {
  129.             string beans;
  130.             string date;
  131.         int amount;
  132.         SYSTEMTIME time;
  133.         GetLocalTime( &time );
  134.            
  135.             ofstream fileout("m:\\coffeeAdd.txt",ios::app);
  136.            
  137.             cout << "Enter beans to append: \n";
  138.             cin >> beans;
  139.             cout << "Please enter date bought: \n";
  140.             cin >> datebought;
  141.             cout << "Please enter amount: \n";
  142.             cin >> amount;
  143.             fileout << beans << "\t" << datebought << "\t" << amount << "\n";
  144.            
  145. ofstream outfile("M:\\coffee1.txt",ios::app);
  146. outfile << beans << "\t""\n";
  147. outfile << amount << "\t""\n";
  148. outfile << date << "\t""\n";
  149.  
  150.  
  151.    fileout.close();
  152.            
  153.     }//end method
  154.            
  155.     void readfile()
  156.     { // open the file from reading into array of records.  Check that the file exists.  Print the contents of the
  157.             //array onto screen.
  158.      
  159.      int count = 0;
  160.      
  161.      ifstream filein("m:\\coffee.txt",ios::in);
  162.      if (!filein)
  163.              {
  164.                      cout << "cannot read file";
  165.                     _getch();
  166.                     exit(1);
  167.             }
  168.      else
  169.      {
  170.              for (count = 0;!filein.eof();count++)
  171.              {
  172.                      filein >> coffee[count].beans >> coffee[count].num_in_stock >> coffee[count].date_purchased;
  173.              }
  174.              filein.close();
  175.      }
  176.      
  177.              //display the file
  178.              for (count=0;count<3;count++)
  179.                      cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t " << coffee[count].date_purchased << "\n";
  180.     }//end of read file method
  181.      
  182.     void date()
  183.     {
  184.             SYSTEMTIME time;
  185.          
  186.         GetLocalTime( &time );
  187.              
  188.             cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
  189.             cout << time.wHour << ":" << time.wMinute << endl;
  190.     }
  191.      
  192.      
  193.     void managermenu()
  194.     {       // screen output given place code araound
  195.                     system("cls");
  196.            
  197.                     cout << "\t\t MANAGER MENU \n";
  198.                     cout << "____________________________________________________\n";
  199.                     cout << "1. View current stock file\n";
  200.                     cout << "2. Add more stock\n";
  201.                     cout << "3. Barrista menu\n";
  202.                     cout << "4.  to Exit\n";
  203.                    
  204.                     cout << "Enter choice: ";
  205.                     cin >> choice;
  206.     }
  207.      
  208.     void manager_act_on_choice()
  209.     {
  210.                     switch(choice)
  211.                     {
  212.                     case 1:
  213.                             {
  214.                                     readfile();
  215.                                     cout<<" This seletion will let you preview current stock";
  216.                                     cout<< "Press any key to continue....";
  217.                                     ch = _getch();
  218.                                      system("pause");
  219.                                     break;
  220.                             }
  221.                     case 2:
  222.                             {
  223.                                     addstock();
  224.                                     cout<<"This seletion will let you add new stock";
  225.                                     ch = _getch();
  226.                                      system("pause");
  227.                                     break;
  228.                             }
  229.                     case 3:
  230.                             {
  231.                                     cout << "This seletion will now take you to the Barrista menu";
  232.                                     cout <<"Press enter key to continue....";
  233.                                     ch = _getch();
  234.                                      //system("pause");
  235.                                     barristamenu();
  236.                                     break;
  237.                             }
  238.                     case 4:
  239.                             {
  240.                                     cout << "do you want to exit? (Y/N): ";
  241.                                     do
  242.                                             che = _getche();
  243.                                     while (che != 'y' && che != 'Y');
  244.                              exit(0);
  245.                             }
  246.                     default: cout << "Error - wrong choice:";
  247.                     }//end switch
  248.     }//end of method
  249.      
  250.      
  251.      
  252.     void barristamenu()
  253.     {       // screen output given place code araound
  254.            
  255.                 system("cls");
  256.      
  257.                     cout << "\t\t BARRISTA MENU \n";
  258.                     cout << "____________________________________________________\n";
  259.                     cout << "1. Make order\n";
  260.                     cout << "2. Update stock file\n";
  261.                     cout << "3.  to Exit (or return to manager menu)\n";
  262.                    
  263.      
  264.                     cout << "Enter choice: ";
  265.                     cin >> choice;
  266.      
  267.     }
  268.     void barrista_act_on_choice()
  269.     {
  270.                     switch(choice)
  271.                     {
  272.                     case 1:
  273.                             {
  274.                                     cout << "This choice will allow you to take an order";
  275.                                     cout <<"Press any key to continue....";
  276.                                     ch = _getch();
  277.                                     break;
  278.                             }
  279.                     case 2:
  280.                             {
  281.                                     cout << "This choice will allow you to append stock";
  282.                                     cout<<"Press any key to continue....";
  283.                                     ch = _getch();
  284.                                     break;
  285.                             }
  286.                    
  287.                     case 3:
  288.                             {
  289.                                     cout << "do you want to exit? (Y/N): ";
  290.                                     do
  291.                                             che = _getche();
  292.                                     while (che != 'y' && che != 'Y');
  293.                              exit(0);
  294.                             }
  295.                     default: cout << "Error - wrong choice:";
  296.                     }//end switch
  297.     }//end of method
  298.      
  299.      
  300.      
  301.      
  302.      
  303.     void display()
  304.     {       int count = 0;
  305.  
  306.  ifstream filein("m:\\coffee.txt",ios::in);
  307.  if (!filein)
  308.          {
  309.                  cout << "Can not open file, please try again";
  310.                 _getch();
  311.                 exit(1);
  312.         }
  313.  else
  314.  {
  315.          for (count = 0;!filein.eof();count++)
  316.          {
  317.                  filein >> coffee[count].beans >> coffee[count].num_in_stock  >> coffee[count].date_purchased;
  318.          }
  319.          filein.close();
  320.  }
  321.  
  322.          //display the file
  323.          for (count=0;count<3;count++)
  324.         cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t" << coffee[count].date_purchased << "\n";
  325.      
  326.            
  327.     }
  328.      
  329.     void processorder( )
  330.     {
  331.             int beans_choice;
  332.             int beans_pos;
  333.             int coffee_choice;
  334.             int portions;
  335.             string coffee;
  336.             int num_cups;
  337.             int total_portions;
  338.      
  339.             system("cls");
  340.      
  341.             cout << "select normal or decaffe" << endl;
  342.             cout << "1. Normal" << endl;
  343.             cout << "2. Decaffe" << endl;
  344.             cout << "Select: ";
  345.             cin >> beans_choice;
  346.             if (beans_choice = 2)
  347.                 beans_pos = 2;
  348.            
  349.     // screen output given place code araound
  350.            
  351.             cout << "\n\n";
  352.             cout << "Now select cofee type" << endl;
  353.             cout << "1. Americano" << endl;
  354.             cout << "2. Macchiato" << endl;
  355.             cout << "3. Espresso" << endl;
  356.             cout << "4. Double Espresso" << endl;
  357.             cout << "5. Cappuccino" << endl;
  358.             cout << "6. Mocha" << endl;
  359.             cin >> beans_choice;
  360.              
  361.      
  362.             cout << "Make selection: ";
  363.             cin >> coffee_choice;
  364.      
  365.   switch(coffee_choice)
  366.                 {
  367.                 case 1:
  368.                         portions = 2;
  369.                                 if(beans_choice == 1)
  370.                                         beans_pos = 0;
  371.                         break;
  372.                 case 2:
  373.                         portions = 2;
  374.                                 if(beans_choice == 1)
  375.                                         beans_pos = 1;
  376.                         break;
  377.                 case 3:
  378.                 portions = 3;
  379.                                 if(beans_choice == 1)
  380.                                         beans_pos = 1;
  381.                         break;
  382.                         case 4:
  383.                 portions = 6;          
  384.                                 if(beans_choice == 1)
  385.                                         beans_pos = 0;
  386.                         break;
  387.                         case 5:
  388.                 portions = 2;                  
  389.                                 if(beans_choice == 1)
  390.                                         beans_pos = 0;
  391.                         break;
  392.                         case 6:
  393.                 portions = 2;
  394.                                 if(beans_choice == 1)
  395.                                         beans_pos = 0;
  396.                         break;
  397.  
  398.                 }
  399.                 cout << "how many cups: ";
  400.                 cin >> num_cups;
  401.  
  402. total_portions = num_cups * portions;
  403.  
  404.         if (total_portions <= coffee[beans_pos])
  405.         {      
  406.                 coffee[beans_pos] = coffee[beans_pos] - total_portions;
  407.                         cout << "order is processed";
  408. }
  409. else
  410. cout << "unavalible due to lack of stock";
  411.  
  412. }
Add Comment
Please, Sign In to add comment