Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <conio.h>
- #include <string>
- #include <windows.h>
- using namespace std;
- const int quit = 7;
- const int MAX = 3;
- struct tm *Sys_T = NULL;
- //set up record structure
- struct coffeerec
- {
- string beansss;
- int num_in_stock;
- string date_purchased;
- };
- typedef coffeerec coffeeArrayType[3];
- coffeeArrayType coffee;
- string uname, password;
- char ch;
- int che;
- int in_sys;
- int choice;
- int amount;
- string datebought;
- void logon();
- void readfile();
- void writefile();
- void managermenu();
- void barristamenu();
- void date();
- void display();
- void processorder();
- void addstock();
- void manager_act_on_choice();
- void barrista_act_on_choice();
- // details of the actual array of records
- void main()
- {
- date();
- logon();
- if (in_sys == 1)
- {
- while (choice !=4)
- {
- managermenu();
- manager_act_on_choice();
- }
- }
- else if (in_sys ==2)
- {
- while (choice !=3)
- {
- barristamenu();
- barrista_act_on_choice();
- }
- }
- }
- void logon()
- {
- cout << "Enter username: " << "\n";
- cin >> uname;
- cout << "Enter Password: " << "\n";
- ch = _getch();
- while (ch!= 13) // 13 is the enter key
- {
- password.push_back(ch);
- cout << "*";
- ch=_getch();
- }
- if (uname.compare ("manager")==0 && password.compare ("man")==0)
- {
- cout << " Hello Boss \n";
- in_sys = 1;
- }
- else if (uname.compare ("barrista")==0 && password.compare ("bar")==0)
- {
- in_sys = 2;
- }
- else
- system("pause");
- cout << "Bah Humbug - Go away";
- }
- void writefile()
- { ofstream fileout("M:\\coffee.txt",ios::out);
- for (int i =0;i<3;i++)
- {
- fileout << coffee[i].beanss <<"\t" << coffee[i].num_in_stock << "\t" << coffee[i].date_purchased << "\n";
- }
- fileout.close();
- }//end method
- void addstock()
- {
- string beans;
- string date;
- int amount;
- SYSTEMTIME time;
- GetLocalTime( &time );
- ofstream fileout("m:\\coffeeAdd.txt",ios::app);
- cout << "Enter beans to append: \n";
- cin >> beans;
- cout << "Please enter date bought: \n";
- cin >> datebought;
- cout << "Please enter amount: \n";
- cin >> amount;
- fileout << beans << "\t" << datebought << "\t" << amount << "\n";
- ofstream outfile("M:\\coffee1.txt",ios::app);
- outfile << beans << "\t""\n";
- outfile << amount << "\t""\n";
- outfile << date << "\t""\n";
- fileout.close();
- }//end method
- void readfile()
- { // open the file from reading into array of records. Check that the file exists. Print the contents of the
- //array onto screen.
- int count = 0;
- ifstream filein("m:\\coffee.txt",ios::in);
- if (!filein)
- {
- cout << "cannot read file";
- _getch();
- exit(1);
- }
- else
- {
- for (count = 0;!filein.eof();count++)
- {
- filein >> coffee[count].beans >> coffee[count].num_in_stock >> coffee[count].date_purchased;
- }
- filein.close();
- }
- //display the file
- for (count=0;count<3;count++)
- cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t " << coffee[count].date_purchased << "\n";
- }//end of read file method
- void date()
- {
- SYSTEMTIME time;
- GetLocalTime( &time );
- cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
- cout << time.wHour << ":" << time.wMinute << endl;
- }
- void managermenu()
- { // screen output given place code araound
- system("cls");
- cout << "\t\t MANAGER MENU \n";
- cout << "____________________________________________________\n";
- cout << "1. View current stock file\n";
- cout << "2. Add more stock\n";
- cout << "3. Barrista menu\n";
- cout << "7 to Exit\n";
- cout << "Enter choice: ";
- cin >> choice;
- }
- void manager_act_on_choice()
- {
- switch(choice)
- {
- case 1:
- {
- readfile();
- cout<<" This seletion will let you preview current stock";
- cout<< "Press any key to continue....";
- ch = _getch();
- system("pause");
- break;
- }
- case 2:
- {
- addstock();
- cout<<"This seletion will let you add new stock";
- ch = _getch();
- system("pause");
- break;
- }
- case 3:
- {
- cout << "This seletion will now take you to the Barrista menu";
- cout<<"Press any key to continue....";
- ch = _getch();
- system("pause");
- break;
- }
- case 4:
- {
- cout << "do you want to exit? (Y/N): ";
- do
- che = _getche();
- while (che != 'y' && che != 'Y');
- exit(0);
- }
- default: cout << "Error - wrong choice:";
- }//end switch
- }//end of method
- void barristamenu()
- { // screen output given place code araound
- system("cls");
- cout << "\t\t BARRISTA MENU \n";
- cout << "____________________________________________________\n";
- cout << "1. Make order\n";
- cout << "2. Update stock file\n";
- cout << "7 to Exit (or return to manager menu)\n";
- cout << "Enter choice: ";
- cin >> choice;
- }
- void barrista_act_on_choice()
- {
- switch(choice)
- {
- case 1:
- {
- cout << "This choice will allow you to take an order";
- cout <<"Press any key to continue....";
- ch = _getch();
- break;
- }
- case 2:
- {
- cout << "This choice will allow you to append stock";
- cout<<"Press any key to continue....";
- ch = _getch();
- break;
- }
- case 3:
- {
- cout << "do you want to exit? (Y/N): ";
- do
- che = _getche();
- while (che != 'y' && che != 'Y');
- exit(0);
- }
- default: cout << "Error - wrong choice:";
- }//end switch
- }//end of method
- void display()
- { int count = 0;
- ifstream filein("m:\\coffee.txt",ios::in);
- if (!filein)
- {
- cout << "Can not open file, please try again";
- _getch();
- exit(1);
- }
- else
- {
- for (count = 0;!filein.eof();count++)
- {
- filein >> coffee[count].beans >> coffee[count].num_in_stock >> coffee[count].date_purchased;
- }
- filein.close();
- }
- //display the file
- for (count=0;count<3;count++)
- cout << coffee[count].beans << "\t" << coffee[count].num_in_stock << "\t" << coffee[count].date_purchased << "\n";
- }
- void processorder( )
- {
- int beans_choice;
- int beans_pos;
- int coffee_choice;
- int portions;
- string coffee;
- int num_cups;
- int total_portions;
- system("cls");
- cout << "select normal or decaffe" << endl;
- cout << "1. Normal" << endl;
- cout << "2. Decaffe" << endl;
- cout << "Select: ";
- cin >> beans_choice;
- if (beans_choice = 2)
- beans_pos = 2;
- // screen output given place code araound
- cout << "\n\n";
- cout << "Now select cofee type" << endl;
- cout << "1. Americano" << endl;
- cout << "2. Macchiato" << endl;
- cout << "3. Espresso" << endl;
- cout << "4. Double Espresso" << endl;
- cout << "5. Cappuccino" << endl;
- cout << "6. Mocha" << endl;
- cin >> beans_choice;
- cout << "Make selection: ";
- cin >> coffee_choice;
- switch(coffee_choice)
- {
- case 1:
- portions = 2;
- if(beans_choice == 1)
- beans_pos = 0;
- break;
- case 2:
- portions = 2;
- if(beans_choice == 1)
- beans_pos = 1;
- break;
- case 3:
- portions = 3;
- if(beans_choice == 1)
- beans_pos = 1;
- break;
- case 4:
- portions = 6;
- if(beans_choice == 1)
- beans_pos = 0;
- break;
- case 5:
- portions = 2;
- if(beans_choice == 1)
- beans_pos = 0;
- break;
- case 6:
- portions = 2;
- if(beans_choice == 1)
- beans_pos = 0;
- break;
- }
- cout << "how many cups: ";
- cin >> num_cups;
- total_portions = num_cups * portions;
- if (total_portions <= coffee[beans_pos].num_in_stock)
- {
- coffee[beans_pos].num_in_stock = coffee[beans_pos].num_in_stock - total_portions;
- cout << "order is processed";
- }
- else
- cout << "unavalible due to lack of stock";
- }
- 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