fork download
  1. /*******************************************************************************
  2. *
  3. * SOME SORT OF TITLE
  4. * ______________________________________________________________________________
  5. *
  6. * This is the the way the description for my code typically
  7. * ______________________________________________________________________________
  8. * INPUT
  9. * input 1 :
  10. * input 2 :
  11. * input 3 :
  12. *
  13. * OUTPUT
  14. * output 2 :
  15. *******************************************************************************/
  16.  
  17. #include <iostream>
  18. #include <iomanip>
  19. #include <cstring>
  20. #include <string>
  21.  
  22. using namespace std;
  23.  
  24. const unsigned short SIZE = 10;
  25. const unsigned short MAX_INPUT_SIZE = 15;
  26.  
  27. //Declare Bin Data Type
  28. struct Bin {
  29. enum PartType { VALVE, BEARING, BUSHING, COUPLING, FLANGE, GEAR, GEAR_HOUSING, VACUUM_GRIPPER, CABLE, ROD};
  30. string binNames[SIZE] = {"Valve", "Bearing", "Bushing", "Coupling", "Flange", "Gear", "Gear Housing", "Vacuum Gripper", "Cable", "Rod"};
  31. int binPartCounts[SIZE] = {10, 5, 15, 21, 7, 5, 5, 25, 18, 12};
  32. int binSize = SIZE;
  33. };
  34.  
  35. struct Menu {
  36. string prompt;
  37. int menuItems;
  38. string errorMessage;
  39.  
  40. };
  41.  
  42. void PrintPart(Bin& bin, Bin::PartType part) {
  43. cout << "Part: " << bin.binNames[part] << ", Count: " << bin.binPartCounts[part] << endl;
  44. }
  45.  
  46. void PrintBin(Bin& bin, int size = SIZE) {
  47. string line = "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
  48. string line2 = "────────────────────────────────────────────────────────────────────────────";
  49.  
  50. cout << line << endl;
  51. cout << left << setw(35) << " Part Description" << left << setw(35) << "Number of Parts in the Bin" << endl;
  52. cout << line2 << endl;
  53. for (int i; i < size; i++) {
  54. cout << " " << left << setw(34) << bin.binNames[i] << setw(35) << bin.binPartCounts[i] << endl;
  55. }
  56. cout << line << endl;
  57. cout << endl;
  58. }
  59.  
  60. bool menuValidation(string input, Menu menu){
  61.  
  62. bool isValid = false;
  63. string placeHolder;
  64.  
  65. for (int i = 0; i < menu.menuItems; i++){
  66. placeHolder = to_string(i + 1);
  67. if (input == placeHolder) {
  68. isValid = true;
  69. }
  70. }
  71.  
  72. return isValid;
  73. }
  74.  
  75. bool partValidation(string input, Bin bin){
  76.  
  77. bool isValid = false;
  78.  
  79. for (int i = 0; i < bin.binSize; i++){
  80. if (input == bin.binNames[i]) {
  81. isValid = true;
  82. }
  83. }
  84.  
  85. return isValid;
  86. }
  87.  
  88. void AddParts(){
  89.  
  90. }
  91.  
  92. void RemoveParts(){
  93.  
  94. }
  95.  
  96. int main() {
  97.  
  98. //Create bin object with the default values
  99. Bin currentBin;
  100.  
  101. //Create menu for choosing to select a bin
  102. Menu binSelection;
  103. binSelection.prompt = "(1) Select a bin\n(2) Exit\n";
  104. binSelection.menuItems = 2;
  105. binSelection.errorMessage = "Invalid input! Please enter 1 or 2.\n";
  106.  
  107. //Create menu for choosing a part bin
  108. Menu partSelection;
  109. partSelection.prompt = "Please enter the name of which part bin you would like to modify: \n";
  110. partSelection.menuItems = 1;
  111. partSelection.errorMessage = "Invalid input! Please enter the exact name of a part.\n";
  112.  
  113. //Create menu for decided what to do with that bin
  114. Menu partModification;
  115. partModification.prompt = "(1) Add parts\n(2) Remove parts\n(3) Select new bin\n(4) Exit\n";
  116. partModification.menuItems = 4;
  117. partModification.errorMessage = "Invalid input! Please enter 1, 2, 3 or 4.\n";
  118.  
  119. //At the beginning we should print the bin so the user can see what they are modifying
  120. PrintBin(currentBin);
  121.  
  122. //Delcaring our input variables;
  123. string inputtedPartName;
  124. string menuOption;
  125.  
  126. //We output the first menu for selecting a bin
  127. cout << binSelection.prompt;
  128. cin >> menuOption;
  129. cout << "User entered: " << menuOption << endl;
  130.  
  131. //Validate the users menu option
  132. while (!menuValidation(menuOption, binSelection)) {
  133. cout << binSelection.errorMessage;
  134. cin >> menuOption;
  135. cout << "User entered: " << menuOption << endl;
  136. }
  137.  
  138. //If we selected 1 we should get the name of the part they want to modfiy
  139. if (menuOption == "1") {
  140.  
  141. //We now prompt for the part name
  142. cout << partSelection.prompt;
  143. cin >> menuOption;
  144. cout << "User entered: " << menuOption << endl;
  145.  
  146. //Check to see if that part is a name in our bin array
  147. while (!partValidation(menuOption, currentBin)){
  148. cout << partSelection.errorMessage;
  149. cin >> menuOption;
  150. cout << "User entered: " << menuOption << endl;
  151. }
  152.  
  153. //Somewhere we need to store the location we are currently preparing to modify
  154.  
  155. //We now ask what the user want to with that part
  156. cout << partModification.prompt;
  157. cin >> menuOption;
  158. cout << "User entered: " << menuOption << endl;
  159.  
  160. //Validate to see if the option chosen was a valid one
  161. while (!menuValidation(menuOption, partModification)){
  162. cout << partModification.errorMessage;
  163. cin >> menuOption;
  164. cout << "User entered: " << menuOption << endl;
  165. }
  166.  
  167.  
  168.  
  169. } else {
  170. //If we didn't select one it means we selected 2 and now need to exit our loop;
  171. }
  172.  
  173.  
  174. return 0;
  175. }
Success #stdin #stdout 0.01s 5316KB
stdin
balls
0
23
1
Tomato
Gear Housing
2
stdout
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Part Description                  Number of Parts in the Bin         
────────────────────────────────────────────────────────────────────────────
 Valve                             10                                 
 Bearing                           5                                  
 Bushing                           15                                 
 Coupling                          21                                 
 Flange                            7                                  
 Gear                              5                                  
 Gear Housing                      5                                  
 Vacuum Gripper                    25                                 
 Cable                             18                                 
 Rod                               12                                 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

(1) Select a bin
(2) Exit
User entered: balls
Invalid input! Please enter 1 or 2.
User entered: 0
Invalid input! Please enter 1 or 2.
User entered: 23
Invalid input! Please enter 1 or 2.
User entered: 1
Please enter the name of which part bin you would like to modify: 
User entered: Tomato
Invalid input! Please enter the exact name of a part.
User entered: Gear
(1) Add parts
(2) Remove parts
(3) Select new bin
(4) Exit
User entered: Housing
Invalid input! Please enter 1, 2, 3 or 4.
User entered: 2