Advertisement
Guest User

programming assignment

a guest
Feb 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <fstream>
  7. #include <cstdio>
  8. #include <cctype>
  9.  
  10. using namespace std;
  11.  
  12. struct listing
  13. {
  14. int itemno,quantity;
  15. char brand[50], stationery[50];
  16. };
  17.  
  18. struct initialise
  19. {
  20. int init, itemsize, brandsize;
  21. };
  22.  
  23. int initialisef();
  24. int menuf();
  25. void listreadf();
  26. int searchid();
  27.  
  28. int main()
  29. {
  30. int menuloop=1, arraysize, menu, idcheck, addsize;
  31. char keyw[50];
  32. struct listing output, display;
  33.  
  34. while (menuloop == 1)
  35. {
  36. ifstream item_num("item number.txt");
  37. ifstream stationery("stationery.txt");
  38. ifstream brand("brand.txt");
  39. ifstream quantity("quantity.txt");
  40.  
  41. arraysize = initialisef();
  42. addsize = arraysize;
  43.  
  44. struct listing* list = NULL;
  45. list = new listing[arraysize];
  46.  
  47. for (int i = 0; i < arraysize; i++)
  48. {
  49. list[i].itemno = 0;
  50. strcpy(list[i].brand,"");
  51. strcpy(list[i].stationery,"");
  52. list[i].quantity = 0;
  53. }
  54.  
  55. while (item_num)
  56. {
  57. for (int i = 0; i < arraysize; i++)
  58. {
  59. item_num >> list[i].itemno;
  60. }
  61. }
  62.  
  63. while (stationery)
  64. {
  65. for (int i = 0; i <= arraysize; i++)
  66. {
  67. stationery.getline(list[i].stationery,50);
  68. }
  69. }
  70.  
  71. while (brand)
  72. {
  73. for (int i = 0; i <= arraysize; i++)
  74. {
  75. brand.getline(list[i].brand,50);
  76. }
  77. }
  78.  
  79. while (quantity)
  80. {
  81. for (int i = 0; i < arraysize; i++)
  82. {
  83. quantity >> list[i].quantity;
  84. }
  85. }
  86.  
  87. menu = menuf();
  88. switch (menu)
  89. {
  90. case 1: // list
  91. system("CLS");
  92. cout << "Item number\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
  93.  
  94. for (int i = 0; i < arraysize; i++)
  95. {
  96. cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << "\t" << setw(6) << list[i].quantity << endl;
  97. }
  98. system("PAUSE");
  99. break;
  100. case 2: // search by item number
  101. idcheck = searchid();
  102.  
  103. for (int i = 0; i < arraysize; i++)
  104. {
  105. if (list[i].itemno == idcheck)
  106. {
  107. display = list[i];
  108. system("CLS");
  109. cout << "Item number";
  110. cout << "\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
  111. cout << setw(7) << display.itemno << "\t\t" << setw(9) << display.stationery << "\t" << setw(9) << display.brand << "\t" << setw(6) << display.quantity << endl;
  112. system("PAUSE");
  113. }
  114. }
  115.  
  116. break;
  117. case 3: // search by keyword
  118. cout << "Enter search keyword: ";
  119. cin >> keyw;
  120.  
  121. for (int i = 0; i < arraysize; i++)
  122. {
  123. cout << keyw;
  124. if (strncmp(list[i].brand,"pen",50) == 0 || strncmp(list[i].stationery,"pen",50) == 0)
  125. {
  126. system("CLS");
  127. cout << "Item number";
  128. cout << "\tStationery";
  129. cout << "\t" << setw(9) <<"Brand" << endl;
  130. cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << endl;
  131. system("PAUSE");
  132. }
  133. else
  134. {
  135. cout << list[i].brand;
  136. system("PAUSE");
  137. }
  138. }
  139.  
  140. break;
  141. case 4: // low inventory
  142.  
  143. system("CLS");
  144. cout << "Item number" << "\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
  145. for (int i = 0; i < arraysize; i++)
  146. {
  147. if ( list[i].quantity < 10)
  148. {
  149. cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << "\t" << setw(6) << list[i].quantity << endl;
  150. }
  151. }
  152. system("PAUSE");
  153.  
  154. break;
  155. case 5: // update
  156. break;
  157. case 6: // add
  158. cout << "Enter";
  159. break;
  160. case 7: // delete
  161. break;
  162. case 8: //exit
  163. menuloop = 0;
  164. break;
  165. default:
  166. menuloop = 1;
  167. break;
  168. }
  169.  
  170. delete[] list;
  171. }
  172.  
  173.  
  174. return 0;
  175. }
  176.  
  177. int initialisef()
  178. {
  179. int out;
  180.  
  181. ifstream initialise("initialise.txt");
  182.  
  183. // checking
  184. if (!initialise)
  185. {
  186. cout << "Error opening the file.\n";
  187. }
  188. else
  189. {
  190. initialise >> out;
  191. }
  192.  
  193. initialise.close();
  194.  
  195. return out;
  196. }
  197.  
  198. int menuf()
  199. {
  200. int input;
  201.  
  202. system("CLS");
  203. cout << "1. List.\n";
  204. cout << "2. Search by item number.\n";
  205. cout << "3. Search by keyword. WIP\n";
  206. cout << "4. Show low inventories.\n";
  207. cout << "5. Update. WIP\n";
  208. cout << "6. Add. WIP\n";
  209. cout << "7. Delete. WIP\n";
  210. cout << "8. Exit.\n";
  211. cin >> input;
  212.  
  213. return input;
  214. }
  215.  
  216. void listread()
  217. {
  218. int listno;
  219.  
  220. system("CLS");
  221. ifstream listfile( "item number.txt" );
  222.  
  223. if (!listfile)
  224. {
  225. cout << "Error opening file.\n";
  226. exit(100);
  227. }
  228. else
  229. {
  230. cout << "Item number" << "\t\tStationery\n";
  231. listfile >> listno;
  232. while (listfile)
  233. {
  234. cout << setw(5) << listno << endl;
  235. listfile >> listno;
  236. }
  237.  
  238. listfile.close();
  239. }
  240. }
  241.  
  242. int searchid()
  243. {
  244. int id;
  245.  
  246. system("CLS");
  247. cout << "\n\n\t\t\t Item number search";
  248. cout << "\n\n\n\tEnter item number to search: ";
  249. cin >> id;
  250.  
  251. return id;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement