Guest User

Untitled

a guest
Jul 4th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.44 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.             {       cout <<"Hello Worker \n";
  101.                     in_sys = 2;
  102.             }
  103.      
  104.      
  105.      
  106.             else
  107.                    
  108.                     cout << "Bah Humbug - Go away";
  109.              system("pause");
  110.            
  111.     }
  112.            
  113.      
  114.     void writefile()
  115.     {        ofstream fileout("M:\\coffee.txt",ios::out);
  116.        
  117.     for (int i =0;i<3;i++)
  118. {
  119.         fileout << coffee[i].beans <<"\t" << coffee[i].num_in_stock  << "\t" << coffee[i].date_purchased << "\n";
  120.        
  121. }
  122.  
  123. fileout.close();    
  124.            
  125.     }//end method
  126.      
  127.      
  128.     void addstock()
  129.     {
  130.             string beans;
  131.             string date;
  132.         int amount;
  133.         SYSTEMTIME time;
  134.         GetLocalTime( &time );
  135.            
  136.             ofstream fileout("m:\\coffeeAdd.txt",ios::app);
  137.            
  138.             cout << "Enter beans to append: \n";
  139.             cin >> beans;
  140.             cout << "Please enter date bought: \n";
  141.             cin >> datebought;
  142.             cout << "Please enter amount: \n";
  143.             cin >> amount;
  144.             fileout << beans << "\t" << datebought << "\t" << amount << "\n";
  145.            
  146. ofstream outfile("M:\\coffee1.txt",ios::app);
  147. outfile << beans << "\t""\n";
  148. outfile << amount << "\t""\n";
  149. outfile << date << "\t""\n";
  150.  
  151.  
  152.    fileout.close();
  153.            
  154.     }//end method
  155.            
  156.     void readfile()
  157.     { // open the file from reading into array of records.  Check that the file exists.  Print the contents of the
  158.             //array onto screen.
  159.      
  160.      int count = 0;
  161.      
  162.      ifstream filein("m:\\coffee.txt",ios::in);
  163.      if (!filein)
  164.              {
  165.                      cout << "cannot read file";
  166.                     _getch();
  167.                     exit(1);
  168.             }
  169.      else
  170.      {
  171.              for (count = 0;!filein.eof();count++)
  172.              {
  173.                      filein >> coffee[count].beans >> coffee[count].num_in_stock >> coffee[count].date_purchased;
  174.              }
  175.              filein.close();
  176.      }
  177.      
  178.              //display the file
  179.              for (count=0;count<3;count++)
  180.                      cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t " << coffee[count].date_purchased << "\n";
  181.     }//end of read file method
  182.      
  183.     void date()
  184.     {
  185.             SYSTEMTIME time;
  186.          
  187.         GetLocalTime( &time );
  188.              
  189.             cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
  190.             cout << time.wHour << ":" << time.wMinute << endl;
  191.     }
  192.      
  193.      
  194.     void managermenu()
  195.     {       // screen output given place code araound
  196.                     system("cls");
  197.            
  198.                     cout << "\t\t MANAGER MENU \n";
  199.                     cout << "____________________________________________________\n";
  200.                     cout << "1. View current stock file\n";
  201.                     cout << "2. Add more stock\n";
  202.                     cout << "3. Barrista menu\n";
  203.                     cout << "4.  to Exit\n";
  204.                    
  205.                     cout << "Enter choice: ";
  206.                     cin >> choice;
  207.     }
  208.      
  209.     void manager_act_on_choice()
  210.     {
  211.                     switch(choice)
  212.                     {
  213.                     case 1:
  214.                             {
  215.                                     readfile();
  216.                                     cout<<" This seletion will let you preview current stock";
  217.                                     cout<< "Press any key to continue....";
  218.                                     ch = _getch();
  219.                                      system("pause");
  220.                                     break;
  221.                             }
  222.                     case 2:
  223.                             {
  224.                                     addstock();
  225.                                     cout<<"This seletion will let you add new stock";
  226.                                     ch = _getch();
  227.                                      system("pause");
  228.                                     break;
  229.                             }
  230.                     case 3:
  231.                             {
  232.                                     cout << "This seletion will now take you to the Barrista menu";
  233.                                     cout <<"Press enter key to continue....";
  234.                                     ch = _getch();
  235.                                      //system("pause");
  236.                                     barristamenu();
  237.                                     break;
  238.                             }
  239.                     case 4:
  240.                             {
  241.                                     cout << "do you want to exit? (Y/N): ";
  242.                                     do
  243.                                             che = _getche();
  244.                                     while (che != 'y' && che != 'Y');
  245.                              exit(0);
  246.                             }
  247.                     default: cout << "Error - wrong choice:";
  248.                     }//end switch
  249.     }//end of method
  250.      
  251.      
  252.      
  253.     void barristamenu()
  254.     {       // screen output given place code araound
  255.            
  256.                 system("cls");
  257.      
  258.                     cout << "\t\t BARRISTA MENU \n";
  259.                     cout << "____________________________________________________\n";
  260.                     cout << "1. Make order\n";
  261.                     cout << "2. Update stock file\n";
  262.                     cout << "3.  to Exit (or return to manager menu)\n";
  263.                    
  264.      
  265.                     cout << "Enter choice: ";
  266.                     cin >> choice;
  267.      
  268.     }
  269.     void barrista_act_on_choice()
  270.     {
  271.                     switch(choice)
  272.                     {
  273.                     case 1:
  274.                             {
  275.                                     cout << "This choice will allow you to take an order";
  276.                                     cout <<"Press any key to continue....";
  277.                                     ch = _getch();
  278.                                     break;
  279.                             }
  280.                     case 2:
  281.                             {
  282.                                     cout << "This choice will allow you to append stock";
  283.                                     cout<<"Press any key to continue....";
  284.                                     ch = _getch();
  285.                                     break;
  286.                             }
  287.                    
  288.                     case 3:
  289.                             {
  290.                                     cout << "do you want to exit? (Y/N): ";
  291.                                     do
  292.                                             che = _getche();
  293.                                     while (che != 'y' && che != 'Y');
  294.                              exit(0);
  295.                             }
  296.                     default: cout << "Error - wrong choice:";
  297.                     }//end switch
  298.     }//end of method
  299.      
  300.      
  301.      
  302.      
  303.      
  304.     void display()
  305.     {       int count = 0;
  306.  
  307.  ifstream filein("m:\\coffee.txt",ios::in);
  308.  if (!filein)
  309.          {
  310.                  cout << "Can not open file, please try again";
  311.                 _getch();
  312.                 exit(1);
  313.         }
  314.  else
  315.  {
  316.          for (count = 0;!filein.eof();count++)
  317.          {
  318.                  filein >> coffee[count].beans >> coffee[count].num_in_stock  >> coffee[count].date_purchased;
  319.          }
  320.          filein.close();
  321.  }
  322.  
  323.          //display the file
  324.          for (count=0;count<3;count++)
  325.         cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t" << coffee[count].date_purchased << "\n";
  326.      
  327.            
  328.     }
  329.      
  330.     void processorder( )
  331.     {
  332.             int beans_choice;
  333.             int beans_pos;
  334.             int coffee_choice;
  335.             int portions;
  336.             string coffee;
  337.             int num_cups;
  338.             int total_portions;
  339.      
  340.             system("cls");
  341.      
  342.             cout << "select normal or decaffe" << endl;
  343.             cout << "1. Normal" << endl;
  344.             cout << "2. Decaffe" << endl;
  345.             cout << "Select: ";
  346.             cin >> beans_choice;
  347.             if (beans_choice = 2)
  348.                 beans_pos = 2;
  349.            
  350.     // screen output given place code araound
  351.            
  352.             cout << "\n\n";
  353.             cout << "Now select cofee type" << endl;
  354.             cout << "1. Americano" << endl;
  355.             cout << "2. Macchiato" << endl;
  356.             cout << "3. Espresso" << endl;
  357.             cout << "4. Double Espresso" << endl;
  358.             cout << "5. Cappuccino" << endl;
  359.             cout << "6. Mocha" << endl;
  360.             cin >> beans_choice;
  361.              
  362.      
  363.             cout << "Make selection: ";
  364.             cin >> coffee_choice;
  365.      
  366.   switch(coffee_choice)
  367.                 {
  368.                 case 1:
  369.                         portions = 2;
  370.                                 if(beans_choice == 1)
  371.                                         beans_pos = 0;
  372.                         break;
  373.                 case 2:
  374.                         portions = 2;
  375.                                 if(beans_choice == 1)
  376.                                         beans_pos = 1;
  377.                         break;
  378.                 case 3:
  379.                 portions = 3;
  380.                                 if(beans_choice == 1)
  381.                                         beans_pos = 1;
  382.                         break;
  383.                         case 4:
  384.                 portions = 6;          
  385.                                 if(beans_choice == 1)
  386.                                         beans_pos = 0;
  387.                         break;
  388.                         case 5:
  389.                 portions = 2;                  
  390.                                 if(beans_choice == 1)
  391.                                         beans_pos = 0;
  392.                         break;
  393.                         case 6:
  394.                 portions = 2;
  395.                                 if(beans_choice == 1)
  396.                                         beans_pos = 0;
  397.                         break;
  398.  
  399.                 }
  400.                 cout << "how many cups: ";
  401.                 cin >> num_cups;
  402.  
  403. total_portions = num_cups * portions;
  404.  
  405.         if (total_portions <= coffee[beans_pos])
  406.         {      
  407.                 coffee[beans_pos] = coffee[beans_pos] - total_portions;
  408.                         cout << "order is processed";
  409. }
  410. else
  411. cout << "unavailable due to lack of stock";
  412.  
  413. }
Add Comment
Please, Sign In to add comment