Guest User

Untitled

a guest
Aug 4th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.70 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.                                                                             processorder();
  279.                                         break;
  280.                                 }
  281.                         case 2:
  282.                                 {
  283.                                         cout << "This choice will allow you to append stock";
  284.                                         cout<<"Press any key to continue....";
  285.                                         ch = _getch();
  286.                                                                             processorder();
  287.                                         break;
  288.                                 }
  289.                        
  290.                         case 3:
  291.                                 {
  292.                                         cout << "do you want to exit? (Y/N): ";
  293.                                         do
  294.                                                 che = _getche();
  295.                                         while (che != 'y' && che != 'Y');
  296.                                  exit(0);
  297.                                 }
  298.                         default: cout << "Error - wrong choice:";
  299.                         }//end switch
  300.         }//end of method
  301.          
  302.          
  303.          
  304.          
  305.          
  306.         void display()
  307.         {       int count = 0;
  308.      
  309.      ifstream filein("m:\\coffee.txt",ios::in);
  310.      if (!filein)
  311.              {
  312.                      cout << "Can not open file, please try again";
  313.                     _getch();
  314.                     exit(1);
  315.             }
  316.      else
  317.      {
  318.              for (count = 0;!filein.eof();count++)
  319.              {
  320.                      filein >> coffee[count].beans >> coffee[count].num_in_stock  >> coffee[count].date_purchased;
  321.              }
  322.              filein.close();
  323.      }
  324.      
  325.              //display the file
  326.              for (count=0;count<3;count++)
  327.             cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t" << coffee[count].date_purchased << "\n";
  328.          
  329.                
  330.         }
  331.          
  332.         void processorder( )
  333.         {
  334.                 int beans_choice;
  335.                 int beans_pos;
  336.                 int coffee_choice;
  337.                 int portions;
  338.                 string coffee;
  339.                 int num_cups;
  340.                 int total_portions;
  341.          
  342.                 system("cls");
  343.          
  344.                 cout << "select normal or decaffe" << endl;
  345.                 cout << "1. Normal" << endl;
  346.                 cout << "2. Decaffe" << endl;
  347.                 cout << "Select: ";
  348.                             cin >> beans_choice;
  349.                             if (beans_choice = 2)
  350.                     beans_pos = 2;
  351.                
  352.         // screen output given place code araound
  353.                
  354.                 cout << "\n\n";
  355.                 cout << "Now select cofee type" << endl;
  356.                 cout << "1. Americano" << endl;
  357.                 cout << "2. Macchiato" << endl;
  358.                 cout << "3. Espresso" << endl;
  359.                 cout << "4. Double Espresso" << endl;
  360.                 cout << "5. Cappuccino" << endl;
  361.                 cout << "6. Mocha" << endl;
  362.                 cin >> beans_choice;
  363.                              
  364.          
  365.                 cout << "Make selection: ";
  366.                 cin >> coffee_choice;
  367.          
  368.       switch(coffee_choice)
  369.                     {
  370.                     case 1:
  371.                             portions = 2;
  372.                                     if(beans_choice == 1)
  373.                                             beans_pos = 0;
  374.                             break;
  375.                     case 2:
  376.                             portions = 2;
  377.                                     if(beans_choice == 1)
  378.                                             beans_pos = 1;
  379.                             break;
  380.                     case 3:
  381.                     portions = 3;
  382.                                     if(beans_choice == 1)
  383.                                             beans_pos = 1;
  384.                             break;
  385.                             case 4:
  386.                     portions = 6;          
  387.                                     if(beans_choice == 1)
  388.                                             beans_pos = 0;
  389.                             break;
  390.                             case 5:
  391.                     portions = 2;                  
  392.                                     if(beans_choice == 1)
  393.                                             beans_pos = 0;
  394.                             break;
  395.                             case 6:
  396.                     portions = 2;
  397.                                     if(beans_choice == 1)
  398.                                             beans_pos = 0;
  399.                             break;
  400.      
  401.                     }
  402.                     cout << "how many cups: ";
  403.                     cin >> num_cups;
  404.      
  405.     total_portions = num_cups * portions;
  406.      
  407.             if (total_portions <= coffee[beans_pos])
  408.             {      
  409.                     coffee[beans_pos] = coffee[beans_pos] - total_portions;
  410.                             cout << "order is processed";
  411.     }
  412.     else
  413.     cout << "unavailable due to lack of stock";
  414.      
  415.     }
Add Comment
Please, Sign In to add comment