Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4. #include <conio.h>
  5. using namespace std;
  6.  
  7. struct pinfo {
  8. int pstock; float pcost; string psku, pname;
  9. };
  10.  
  11. //Creation of the arrays, split into 2 in order to allow for both strings and number values to be set in the "same" place.
  12. const int maxproduct = 9;
  13. const int provals = 2;
  14. string protxt [maxproduct] [provals];
  15. float prono [maxproduct] [provals];
  16.  
  17. //Prototypes declared here.
  18. int IMSCONSOLE(), IMSADD(), IMSREM(), IMSVIEW(), IMSWRITE(), login();
  19.  
  20. int main()
  21. {
  22. cout << "IIIIIIIIIIMMMMMMMM MMMMMMMM SSSSSSSSSSSSSSS \n";Sleep(100);
  23. cout << "I::::::::IM:::::::M M:::::::M SS:::::::::::::::S\n";Sleep(100);
  24. cout << "I::::::::IM::::::::M M::::::::MS:::::SSSSSS::::::S\n";Sleep(100);
  25. cout << "II::::::IIM:::::::::M M:::::::::MS:::::S SSSSSSS\n";Sleep(100);
  26. cout << " I::::I M::::::::::M M::::::::::MS:::::S \n";Sleep(100);
  27. cout << " I::::I M:::::::::::M M:::::::::::MS:::::S \n";Sleep(100);
  28. cout << " I::::I M:::::::M::::M M::::M:::::::M S::::SSSS \n";Sleep(100);
  29. cout << " I::::I M::::::M M::::M M::::M M::::::M SS::::::SSSSS \n";Sleep(100);
  30. cout << " I::::I M::::::M M::::M::::M M::::::M SSS::::::::SS \n";Sleep(100);
  31. cout << " I::::I M::::::M M:::::::M M::::::M SSSSSS::::S \n";Sleep(100);
  32. cout << " I::::I M::::::M M:::::M M::::::M S:::::S\n";Sleep(100);
  33. cout << " I::::I M::::::M MMMMM M::::::M S:::::S\n";Sleep(100);
  34. cout << "II::::::IIM::::::M M::::::MSSSSSSS S:::::S\n";Sleep(100);
  35. cout << "I::::::::IM::::::M M::::::MS::::::SSSSSS:::::S\n";Sleep(100);
  36. cout << "I::::::::IM::::::M M::::::MS:::::::::::::::SS \n";Sleep(100);
  37. cout << "IIIIIIIIIIMMMMMMMM MMMMMMMM SSSSSSSSSSSSSSS \n";Sleep(100);
  38. cout<< "\n Welcome to the Inventory Management System.";
  39. login();
  40. }
  41.  
  42. int login()
  43. {
  44. //Yes, storing login details in plaintext is a no-no. However, I don't think it matters here.
  45. string validusers ="admin";
  46. string validpass = "ILOVETHEROCK!";
  47. string userentry;
  48. string passentry;
  49. cout<<"\n\nPlease enter your username:";
  50. cin>>userentry;
  51. cout<<"\nPlease enter your password:";
  52. cin>>passentry;
  53.  
  54. //If both are correct, go to console. anything else retry.
  55.  
  56.  
  57. if ((userentry == validusers) && (passentry == validpass)){
  58. cout<<"Welcome back! Press any key to continue. \n\n";
  59. getch();
  60. system("CLS");
  61. IMSCONSOLE();
  62. }
  63. else{
  64. cout<<"Sorry, either your username or password was incorrect. Please try again.";
  65. Sleep(2000);
  66. system("CLS");
  67. main();
  68. }
  69. return 0;
  70. }
  71.  
  72.  
  73.  
  74. int IMSVIEW()
  75. {
  76. //Pretty self-explanatory, uses for loop to spit out based on the size of the array.
  77. // Technically, maxproduct could have been declared by the user and probably should be in a practical inventory manager, but for simplicity it was not.
  78. cout<<"This is our current inventory:\n";
  79. cout<<"Product Names | Product SKU | Product Stock | Product Cost\n\n";
  80. for (int i=0; i<maxproduct; ++i)
  81. {
  82. cout<<i+1<<":"<<protxt [i] [0] << "|"<<protxt [i] [1] << "|"<<prono [i] [0] << "|"<<prono [i] [1]<<endl;
  83. }
  84. cout<<"\n Press any key to continue.";
  85. getch();
  86. return IMSCONSOLE();
  87. }
  88.  
  89. int IMSADD()
  90. {
  91.  
  92. int rowchoice=0;
  93. 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";
  94. cin>>rowchoice;
  95. if (rowchoice == 0)
  96. {
  97. return IMSCONSOLE();
  98. }
  99. else
  100. {
  101. //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.
  102. //struct used here to fill array.
  103. pinfo newproduct;
  104. rowchoice = rowchoice -1;
  105. cout<<"\n\nEnter the Product Name: ";
  106. cin>>newproduct.pname;
  107. cout<<"\n\n Enter the Product SKU tag: ";
  108. cin>>newproduct.psku;
  109. cout<<"\n\n Enter the Product Stock: ";
  110. cin>>newproduct.pstock;
  111. cout<<"\n\n Enter the Product Cost in USD: ";
  112. cin>>newproduct.pcost;
  113.  
  114. cout<<"\n\n This is what was entered:";
  115. cout<<endl<<"Name: "<<newproduct.pname<<endl<<"SKU: "<<newproduct.psku<<endl<<newproduct.pstock<<" In Stock"<<endl<<"Cost: $"<<newproduct.pcost<<"\n\n";
  116. protxt [rowchoice] [0] = newproduct.pname;
  117. protxt [rowchoice] [1] = newproduct.psku;
  118. prono [rowchoice] [0] = newproduct.pstock;
  119. prono [rowchoice] [1] = newproduct.pcost;
  120. cout<<"\n Press any key to continue.";
  121. getch();
  122. return IMSCONSOLE();
  123. }
  124. }
  125. int IMSREM()
  126. {
  127. //Same mechanism as IMSADD for rows.
  128.  
  129. int rowchoice=0;
  130. 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";
  131. cin>>rowchoice;
  132.  
  133. if (rowchoice == 0)
  134. {
  135. return IMSCONSOLE();
  136. }
  137.  
  138. //If you choose a row that doesn't exist, you delete nothing.
  139.  
  140. else
  141. {
  142. rowchoice = rowchoice -1;
  143. int dblcheck;
  144.  
  145. //In case you accidentally choose the wrong row.
  146. cout<<"Are you sure? Doing this will permanently delete the values set for that product.\n\n 1. Yes \n 2. No\n ";
  147. cin>> dblcheck;
  148. if (dblcheck == 1)
  149. {
  150. //Sets all values to zero or empty.
  151.  
  152. protxt [rowchoice] [0] = "";
  153. protxt [rowchoice] [1] = "";
  154. prono [rowchoice] [0] = 0;
  155. prono [rowchoice] [1] = 0;
  156. cout<<"\n Done! Press any key to continue.";
  157. getch();
  158. return IMSCONSOLE();
  159. }
  160. if (dblcheck == 0)
  161. {
  162. return IMSCONSOLE();
  163. }
  164.  
  165. //Bug catcher
  166. else{
  167. cout<<"Invalid Entry.";
  168. return IMSREM();
  169. }
  170. }
  171.  
  172. }
  173. //The 'Not learned in class' portion is here.
  174. int IMSWRITE()
  175. {
  176. ofstream myfile;
  177.  
  178. //Creates new text file
  179. myfile.open ("savedata.txt");
  180.  
  181. //Output for loop spits into the new text file
  182. for (int i=0; i<maxproduct; ++i)
  183. {
  184. myfile<<i+1<<":"<<protxt [i] [0] << "|"<<protxt [i] [1] << "|"<<prono [i] [0] << "|"<<prono [i] [1]<<endl;
  185. }
  186. myfile.close();
  187.  
  188. // Closed the file. Time to leave.
  189. cout<<"\n\n Saved! Check 'savedata.txt'";
  190. Sleep(2000);
  191. system("CLS");
  192. return IMSCONSOLE();
  193. }
  194.  
  195. //Start of the function tree. All roads lead to IMSCONSOLE()
  196. int IMSCONSOLE()
  197. {
  198. int menuchoice;
  199. do {
  200. 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;
  201. cin >>menuchoice;
  202.  
  203. //Bad Input Catcher
  204. if ((menuchoice >5) && (menuchoice <1)) {
  205. cout <<"That choice is not a valid option. Please choose one of the options above.";
  206. Sleep(2500);
  207. system("CLS");
  208. return IMSCONSOLE();
  209. }
  210.  
  211. //The Normal stuff, sends to individual defined functions in each case spare 5.
  212.  
  213. switch (menuchoice)
  214. {
  215. case 1:
  216. IMSVIEW();
  217. break;
  218.  
  219.  
  220. case 2:
  221. IMSADD();
  222. break;
  223.  
  224. case 3:
  225. IMSREM();
  226. break;
  227.  
  228. case 4:
  229. IMSWRITE();
  230. break;
  231.  
  232. case 5:
  233. cout<<"\n Thank you for using the IMS system. Goodbye!";
  234. Sleep(1000);
  235. return 0;
  236. }
  237. } while (menuchoice != 5);
  238. return 0;
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement