Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- struct pinfo {
- int pstock; float pcost; string psku, pname;
- };
- //Creation of the arrays, split into 2 in order to allow for both strings and number values to be set in the "same" place.
- const int maxproduct = 9;
- const int provals = 2;
- string protxt [maxproduct] [provals];
- float prono [maxproduct] [provals];
- //Prototypes declared here.
- int IMSCONSOLE(), IMSADD(), IMSREM(), IMSVIEW(), IMSWRITE(), login();
- int main()
- {
- cout << "IIIIIIIIIIMMMMMMMM MMMMMMMM SSSSSSSSSSSSSSS \n";Sleep(100);
- cout << "I::::::::IM:::::::M M:::::::M SS:::::::::::::::S\n";Sleep(100);
- cout << "I::::::::IM::::::::M M::::::::MS:::::SSSSSS::::::S\n";Sleep(100);
- cout << "II::::::IIM:::::::::M M:::::::::MS:::::S SSSSSSS\n";Sleep(100);
- cout << " I::::I M::::::::::M M::::::::::MS:::::S \n";Sleep(100);
- cout << " I::::I M:::::::::::M M:::::::::::MS:::::S \n";Sleep(100);
- cout << " I::::I M:::::::M::::M M::::M:::::::M S::::SSSS \n";Sleep(100);
- cout << " I::::I M::::::M M::::M M::::M M::::::M SS::::::SSSSS \n";Sleep(100);
- cout << " I::::I M::::::M M::::M::::M M::::::M SSS::::::::SS \n";Sleep(100);
- cout << " I::::I M::::::M M:::::::M M::::::M SSSSSS::::S \n";Sleep(100);
- cout << " I::::I M::::::M M:::::M M::::::M S:::::S\n";Sleep(100);
- cout << " I::::I M::::::M MMMMM M::::::M S:::::S\n";Sleep(100);
- cout << "II::::::IIM::::::M M::::::MSSSSSSS S:::::S\n";Sleep(100);
- cout << "I::::::::IM::::::M M::::::MS::::::SSSSSS:::::S\n";Sleep(100);
- cout << "I::::::::IM::::::M M::::::MS:::::::::::::::SS \n";Sleep(100);
- cout << "IIIIIIIIIIMMMMMMMM MMMMMMMM SSSSSSSSSSSSSSS \n";Sleep(100);
- cout<< "\n Welcome to the Inventory Management System.";
- login();
- }
- int login()
- {
- //Yes, storing login details in plaintext is a no-no. However, I don't think it matters here.
- string validusers ="admin";
- string validpass = "ILOVETHEROCK!";
- string userentry;
- string passentry;
- cout<<"\n\nPlease enter your username:";
- cin>>userentry;
- cout<<"\nPlease enter your password:";
- cin>>passentry;
- //If both are correct, go to console. anything else retry.
- if ((userentry == validusers) && (passentry == validpass)){
- cout<<"Welcome back! Press any key to continue. \n\n";
- getch();
- system("CLS");
- IMSCONSOLE();
- }
- else{
- cout<<"Sorry, either your username or password was incorrect. Please try again.";
- Sleep(2000);
- system("CLS");
- main();
- }
- return 0;
- }
- int IMSVIEW()
- {
- //Pretty self-explanatory, uses for loop to spit out based on the size of the array.
- // Technically, maxproduct could have been declared by the user and probably should be in a practical inventory manager, but for simplicity it was not.
- cout<<"This is our current inventory:\n";
- cout<<"Product Names | Product SKU | Product Stock | Product Cost\n\n";
- for (int i=0; i<maxproduct; ++i)
- {
- cout<<i+1<<":"<<protxt [i] [0] << "|"<<protxt [i] [1] << "|"<<prono [i] [0] << "|"<<prono [i] [1]<<endl;
- }
- cout<<"\n Press any key to continue.";
- getch();
- return IMSCONSOLE();
- }
- int IMSADD()
- {
- int rowchoice=0;
- cout<<"Which line would you like to write over? Type '0' to exit back to the console. \n (Warning: If you choose a line with data existing, it will be overwritten!) \n";
- cin>>rowchoice;
- if (rowchoice == 0)
- {
- return IMSCONSOLE();
- }
- else
- {
- //The line rowchoice = rowchoice-1 converts the plain text 1-10 rows into how the computer reads them as 0-9. Easier for non-computer savvy users.
- //struct used here to fill array.
- pinfo newproduct;
- rowchoice = rowchoice -1;
- cout<<"\n\nEnter the Product Name: ";
- cin>>newproduct.pname;
- cout<<"\n\n Enter the Product SKU tag: ";
- cin>>newproduct.psku;
- cout<<"\n\n Enter the Product Stock: ";
- cin>>newproduct.pstock;
- cout<<"\n\n Enter the Product Cost in USD: ";
- cin>>newproduct.pcost;
- cout<<"\n\n This is what was entered:";
- cout<<endl<<"Name: "<<newproduct.pname<<endl<<"SKU: "<<newproduct.psku<<endl<<newproduct.pstock<<" In Stock"<<endl<<"Cost: $"<<newproduct.pcost<<"\n\n";
- protxt [rowchoice] [0] = newproduct.pname;
- protxt [rowchoice] [1] = newproduct.psku;
- prono [rowchoice] [0] = newproduct.pstock;
- prono [rowchoice] [1] = newproduct.pcost;
- cout<<"\n Press any key to continue.";
- getch();
- return IMSCONSOLE();
- }
- }
- int IMSREM()
- {
- //Same mechanism as IMSADD for rows.
- int rowchoice=0;
- cout<<"Which line would you like to delete over? Type '0' to exit back to the console. \n (Warning: If you choose a line with data existing, it will be overwritten!) \n";
- cin>>rowchoice;
- if (rowchoice == 0)
- {
- return IMSCONSOLE();
- }
- //If you choose a row that doesn't exist, you delete nothing.
- else
- {
- rowchoice = rowchoice -1;
- int dblcheck;
- //In case you accidentally choose the wrong row.
- cout<<"Are you sure? Doing this will permanently delete the values set for that product.\n\n 1. Yes \n 2. No\n ";
- cin>> dblcheck;
- if (dblcheck == 1)
- {
- //Sets all values to zero or empty.
- protxt [rowchoice] [0] = "";
- protxt [rowchoice] [1] = "";
- prono [rowchoice] [0] = 0;
- prono [rowchoice] [1] = 0;
- cout<<"\n Done! Press any key to continue.";
- getch();
- return IMSCONSOLE();
- }
- if (dblcheck == 0)
- {
- return IMSCONSOLE();
- }
- //Bug catcher
- else{
- cout<<"Invalid Entry.";
- return IMSREM();
- }
- }
- }
- //The 'Not learned in class' portion is here.
- int IMSWRITE()
- {
- ofstream myfile;
- //Creates new text file
- myfile.open ("savedata.txt");
- //Output for loop spits into the new text file
- for (int i=0; i<maxproduct; ++i)
- {
- myfile<<i+1<<":"<<protxt [i] [0] << "|"<<protxt [i] [1] << "|"<<prono [i] [0] << "|"<<prono [i] [1]<<endl;
- }
- myfile.close();
- // Closed the file. Time to leave.
- cout<<"\n\n Saved! Check 'savedata.txt'";
- Sleep(2000);
- system("CLS");
- return IMSCONSOLE();
- }
- //Start of the function tree. All roads lead to IMSCONSOLE()
- int IMSCONSOLE()
- {
- int menuchoice;
- do {
- cout << "\n\n What would you like to do? Type in the desired number to choose. \n\n 1. View Products \n 2. Add a Product \n 3. Delete a Product \n 4. Save to File \n 5. Exit \n\n" << endl;
- cin >>menuchoice;
- //Bad Input Catcher
- if ((menuchoice >5) && (menuchoice <1)) {
- cout <<"That choice is not a valid option. Please choose one of the options above.";
- Sleep(2500);
- system("CLS");
- return IMSCONSOLE();
- }
- //The Normal stuff, sends to individual defined functions in each case spare 5.
- switch (menuchoice)
- {
- case 1:
- IMSVIEW();
- break;
- case 2:
- IMSADD();
- break;
- case 3:
- IMSREM();
- break;
- case 4:
- IMSWRITE();
- break;
- case 5:
- cout<<"\n Thank you for using the IMS system. Goodbye!";
- Sleep(1000);
- return 0;
- }
- } while (menuchoice != 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement