Guest User

Untitled

a guest
Jan 7th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cctype>
  4. #include<iomanip>
  5.  
  6. class legoset
  7. {
  8. char setcatname[25];
  9. char name[50];
  10. char legoinclude[25];
  11. char legotype[25];
  12.  
  13. public:
  14. void create_category();
  15. void show_category() const;
  16. void modify();
  17. void report() const;
  18. int retacno() const;
  19. };
  20.  
  21. void legoset::create_category()
  22. {
  23. std::cout << "Please enter a category name : n";
  24. std::cin >> setcatname;
  25. //std::cin.getline(setcatname, 25);
  26. std::cout << "Please enter your username! n";
  27. std::cin >> name;
  28. std::cin.ignore();
  29. std::cin.getline(name, 50);
  30. std::cout << name << " , is it a vehicle or building (V/B)?n";
  31. std::cin >> legotype;
  32. legotype[25] = toupper(legotype[25]);
  33. std::cin.getline(legotype, 25);
  34. std::cout << "n Please enter the name of the lego set. n";
  35. std::cin >> legoinclude;
  36. //std::cin.getline(legoinclude, 25);
  37. std::cout << "nn Category Created Successfully!!!";
  38.  
  39. return;
  40. }
  41.  
  42. void legoset::show_category() const
  43. {
  44. std::cout << "Category : n" << setcatname;
  45. std::cout << "Username Of Holder n: " << name;
  46. std::cout << " Lego type (B/V) : " << legotype;
  47. std::cout << " Lego set (with details) : " << legoinclude;
  48. return;
  49. }
  50.  
  51. void legoset::modify()
  52. {
  53. std::cout << "Category : n" << setcatname[25];
  54. std::cout << "nModify Holder's name : ";
  55. std::cin.ignore();
  56. std::cin.getline(name, 50);
  57. std::cout << "nModify A Building or vehicle class ( B/V ) : ";
  58. std::cin >> legotype[25];
  59. legotype[25] = toupper(legotype[25]);
  60. std::cout << "nModify Lego set (with details) : ";
  61. std::cin >> legoinclude[25];
  62. }
  63.  
  64. void legoset::report() const
  65. {
  66. std::cout << setcatname[25] << std::setw(10) << " " << name << std::setw(10) << " " << legotype[25] << std::setw(6) << legoinclude[25] << std::endl;
  67. }
  68.  
  69. int legoset::retacno() const
  70. {
  71. return setcatname[25];
  72. }
  73.  
  74.  
  75. void write_legoset(); //function to write record in binary file
  76. void display_sp(int); //function to display account details given by user
  77. void modify_set(int); //function to modify record of file
  78. void delete_set(int); //function to delete record of file
  79. void display_all(); //function to display all account details
  80. void intro(); //introductory screen function
  81.  
  82.  
  83. int main()
  84. {
  85. char choice;
  86. int num;
  87. intro();
  88. do
  89. {
  90. system("cls");
  91. std::cout << "nnntMAIN MENU";
  92. std::cout << "nnt01. New Category";
  93. std::cout << "nnt02. ADD A NEW SET";
  94. std::cout << "nnt03. ALL USERS HOLDER LIST";
  95. std::cout << "nnt04. DELETE A CATEGORY";
  96. std::cout << "nnt05. MODIFY A CATEGORY";
  97. std::cout << "nnt06. EXIT";
  98. std::cout << "nntSelect Your Option (1-6) ";
  99. std::cin >> choice;
  100. system("cls");
  101. switch (choice)
  102. {
  103. case '1':
  104. write_legoset();
  105. break;
  106. case '2':
  107. std::cout << "nntEnter The category Name : "; std::cin >> num;
  108. display_sp(num);
  109. break;
  110. case '3':
  111. display_all();
  112. break;
  113. case '4':
  114. std::cout << "nntEnter The Category Name : "; std::cin >> num;
  115. delete_set(num);
  116. break;
  117. case '5':
  118. std::cout << "nntEnter The Category Name : "; std::cin >> num;
  119. modify_set(num);
  120. break;
  121. case '6':
  122. std::cout << "nntThanks for using lego managemnt system!";
  123. std::exit;
  124. break;
  125. default: std::cout << "a";
  126. }
  127. std::cin.ignore();
  128. std::cin.get();
  129. } while (choice != '6');
  130. return 0;
  131. }
  132.  
  133. //***************************************************************
  134. // function to write in file
  135. //****************************************************************
  136.  
  137. void write_legoset()
  138. {
  139. legoset lego;
  140. std::ofstream outFile;
  141. outFile.open("legoset.dat", std::ios::binary | std::ios::app);
  142. lego.create_category();
  143. outFile.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
  144. outFile.close();
  145. }
  146.  
  147. //***************************************************************
  148. // function to read specific record from file
  149. //****************************************************************
  150.  
  151. void display_sp(int n)
  152. {
  153. legoset lego;
  154. bool flag = false;
  155. std::ifstream inFile;
  156. inFile.open("legoset.dat", std::ios::binary);
  157. if (!inFile)
  158. {
  159. std::cout << "File could not be open !! Press any Key...";
  160. return;
  161. }
  162. std::cout << "nLEGOSET DETAILSn";
  163.  
  164. while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
  165. {
  166. if (lego.retacno() == n)
  167. {
  168. lego.show_category();
  169. flag = true;
  170. }
  171. }
  172. inFile.close();
  173. if (flag == false)
  174. std::cout << "nnLego set does not exist in this file";
  175. }
  176.  
  177. //***************************************************************
  178. // function to modify record of file
  179. //****************************************************************
  180.  
  181. void modify_set(int n)
  182. {
  183. bool found = false;
  184. legoset lego;
  185. std::fstream File;
  186. File.open("legoset.dat", std::ios::binary | std::ios::in | std::ios::out);
  187. if (!File)
  188. {
  189. std::cout << "File could not be open !! Press any Key...";
  190. return;
  191. }
  192. while (!File.eof() && found == false)
  193. {
  194. File.read(reinterpret_cast<char *> (&lego), sizeof(legoset));
  195. if (lego.retacno() == n)
  196. {
  197. lego.show_category();
  198. std::cout << "nnPlease Enter The New Details For This Category." << std::endl;
  199. lego.modify();
  200. int pos = (-1)*static_cast<int>(sizeof(legoset));
  201. File.seekp(pos, std::ios::cur);
  202. File.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
  203. std::cout << "nnt Category Updated!";
  204. found = true;
  205. }
  206. }
  207. File.close();
  208. if (found == false)
  209. std::cout << "nn Category Not Found ";
  210. }
  211.  
  212. //***************************************************************
  213. // function to delete record of file
  214. //****************************************************************
  215.  
  216.  
  217. void delete_set(int n)
  218. {
  219. legoset lego;
  220. std::ifstream inFile;
  221. std::ofstream outFile;
  222. inFile.open("legoset.dat", std::ios::binary);
  223. if (!inFile)
  224. {
  225. std::cout << "File could not be open !! Press any Key...";
  226. return;
  227. }
  228. outFile.open("Temp.dat", std::ios::binary);
  229. inFile.seekg(0, std::ios::beg);
  230. while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
  231. {
  232. if (lego.retacno() != n)
  233. {
  234. outFile.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
  235. }
  236. }
  237. inFile.close();
  238. outFile.close();
  239. remove("legoset.dat");
  240. rename("Temp.dat", "legoset.dat");
  241. std::cout << "nntCategory Deleted ..";
  242. }
  243.  
  244.  
  245. //***************************************************************
  246. // function to display all accounts deposit list
  247. //****************************************************************
  248.  
  249.  
  250. void display_all()
  251. {
  252. legoset lego;
  253. std::ifstream inFile;
  254. inFile.open("legoset.dat", std::ios::binary);
  255. if (!inFile)
  256. {
  257. std::cout << "File could not be open !! Press any Key...";
  258. return;
  259. }
  260. std::cout << "nnttUSER HOLDER LISTnn";
  261. std::cout << "====================================================n";
  262. std::cout << "A/c no. NAME Type Balancen";
  263. std::cout << "====================================================n";
  264. while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
  265. {
  266. lego.report();
  267. }
  268. inFile.close();
  269. }
  270.  
  271. void intro()
  272. {
  273. std::cout << "nnnt LEGOSET";
  274. std::cout << "nntMANAGEMENT";
  275. std::cout << "nnt SYSTEM";
  276. std::cout << "nnnnMADE BY : Philippe Barry";
  277. std::cin.get();
  278. }
  279.  
  280. //***************************************************************
  281. // END OF PROJECT
  282. //***************************************************************
Add Comment
Please, Sign In to add comment