Guest User

Untitled

a guest
Jun 29th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.55 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 beansss;
  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].beanss <<"\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 << "7  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 any key to continue....";
  233.                                     ch = _getch();
  234.                                      system("pause");
  235.                                     break;
  236.                             }
  237.                     case 4:
  238.                             {
  239.                                     cout << "do you want to exit? (Y/N): ";
  240.                                     do
  241.                                             che = _getche();
  242.                                     while (che != 'y' && che != 'Y');
  243.                              exit(0);
  244.                             }
  245.                     default: cout << "Error - wrong choice:";
  246.                     }//end switch
  247.     }//end of method
  248.      
  249.      
  250.      
  251.     void barristamenu()
  252.     {       // screen output given place code araound
  253.            
  254.                 system("cls");
  255.      
  256.                     cout << "\t\t BARRISTA MENU \n";
  257.                     cout << "____________________________________________________\n";
  258.                     cout << "1. Make order\n";
  259.                     cout << "2. Update stock file\n";
  260.                     cout << "7  to Exit (or return to manager menu)\n";
  261.      
  262.                     cout << "Enter choice: ";
  263.                     cin >> choice;
  264.      
  265.     }
  266.     void barrista_act_on_choice()
  267.     {
  268.                     switch(choice)
  269.                     {
  270.                     case 1:
  271.                             {
  272.                                     cout << "This choice will allow you to take an order";
  273.                                     cout <<"Press any key to continue....";
  274.                                     ch = _getch();
  275.                                     break;
  276.                             }
  277.                     case 2:
  278.                             {
  279.                                     cout << "This choice will allow you to append stock";
  280.                                     cout<<"Press any key to continue....";
  281.                                     ch = _getch();
  282.                                     break;
  283.                             }
  284.                    
  285.                     case 3:
  286.                             {
  287.                                     cout << "do you want to exit? (Y/N): ";
  288.                                     do
  289.                                             che = _getche();
  290.                                     while (che != 'y' && che != 'Y');
  291.                              exit(0);
  292.                             }
  293.                     default: cout << "Error - wrong choice:";
  294.                     }//end switch
  295.     }//end of method
  296.      
  297.      
  298.      
  299.      
  300.      
  301.     void display()
  302.     {       int count = 0;
  303.  
  304.  ifstream filein("m:\\coffee.txt",ios::in);
  305.  if (!filein)
  306.          {
  307.                  cout << "Can not open file, please try again";
  308.                 _getch();
  309.                 exit(1);
  310.         }
  311.  else
  312.  {
  313.          for (count = 0;!filein.eof();count++)
  314.          {
  315.                  filein >> coffee[count].beans >> coffee[count].num_in_stock  >> coffee[count].date_purchased;
  316.          }
  317.          filein.close();
  318.  }
  319.  
  320.          //display the file
  321.          for (count=0;count<3;count++)
  322.         cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t" << coffee[count].date_purchased << "\n";
  323.      
  324.            
  325.     }
  326.      
  327.     void processorder( )
  328.     {
  329.             int beans_choice;
  330.             int beans_pos;
  331.             int coffee_choice;
  332.             int portions;
  333.             string coffee;
  334.             int num_cups;
  335.             int total_portions;
  336.      
  337.             system("cls");
  338.      
  339.             cout << "select normal or decaffe" << endl;
  340.             cout << "1. Normal" << endl;
  341.             cout << "2. Decaffe" << endl;
  342.             cout << "Select: ";
  343.             cin >> beans_choice;
  344.             if (beans_choice = 2)
  345.                 beans_pos = 2;
  346.            
  347.     // screen output given place code araound
  348.            
  349.             cout << "\n\n";
  350.             cout << "Now select cofee type" << endl;
  351.             cout << "1. Americano" << endl;
  352.             cout << "2. Macchiato" << endl;
  353.             cout << "3. Espresso" << endl;
  354.             cout << "4. Double Espresso" << endl;
  355.             cout << "5. Cappuccino" << endl;
  356.             cout << "6. Mocha" << endl;
  357.             cin >> beans_choice;
  358.              
  359.      
  360.             cout << "Make selection: ";
  361.             cin >> coffee_choice;
  362.      
  363.   switch(coffee_choice)
  364.                 {
  365.                 case 1:
  366.                         portions = 2;
  367.                                 if(beans_choice == 1)
  368.                                         beans_pos = 0;
  369.                         break;
  370.                 case 2:
  371.                         portions = 2;
  372.                                 if(beans_choice == 1)
  373.                                         beans_pos = 1;
  374.                         break;
  375.                 case 3:
  376.                 portions = 3;
  377.                                 if(beans_choice == 1)
  378.                                         beans_pos = 1;
  379.                         break;
  380.                         case 4:
  381.                 portions = 6;          
  382.                                 if(beans_choice == 1)
  383.                                         beans_pos = 0;
  384.                         break;
  385.                         case 5:
  386.                 portions = 2;                  
  387.                                 if(beans_choice == 1)
  388.                                         beans_pos = 0;
  389.                         break;
  390.                         case 6:
  391.                 portions = 2;
  392.                                 if(beans_choice == 1)
  393.                                         beans_pos = 0;
  394.                         break;
  395.  
  396.                 }
  397.                 cout << "how many cups: ";
  398.                 cin >> num_cups;
  399.  
  400. total_portions = num_cups * portions;
  401.  
  402.         if (total_portions <= coffee[beans_pos].num_in_stock)
  403.         {      
  404.                 coffee[beans_pos].num_in_stock = coffee[beans_pos].num_in_stock - total_portions;
  405.                         cout << "order is processed";
  406. }
  407. else
  408. cout << "unavalible due to lack of stock";
  409.  
  410. }
  411.                    
  412.    
  413.  quit = 7; const int MAX = 3; string uname, password; char ch; int che; int in_sys; int choice; struct tm *Sys_T = NULL;
Add Comment
Please, Sign In to add comment