Advertisement
Guest User

campus_shop_v2

a guest
Oct 20th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip> //setw
  3. #include <cmath> // math
  4. #include <fstream>
  5. #include <cstring>
  6. #include <string>
  7. #include <map>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. // Big Daddy Menu ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  19.  
  20. // hey future coder, when menu is written it needs parameters
  21. // username,
  22.  
  23. void menu(string username, string password) {
  24. double const SALES_TAX = .06875;
  25. string menu_setup, line, search, search1, key, price, psearch, psearch1;
  26. string buy_statement, return_statement, cart_statement; // this are size_t price_initial, price_final;
  27. string divvy = "======================================\n";
  28. int opt, current_money, price_int;
  29. int n1,n4; // counters for reading lines
  30. int ben = 1; // ben runs everything
  31.  
  32. cout << "CAMPUS_SHOP_V2\n" << divvy << "\n";
  33.  
  34. menu_setup = "\n1.Buy\n2.Return\n3.List\n4.Cart\n5.Quit\n>";
  35.  
  36. fstream inventory;
  37. fstream cart;
  38. fstream inv_source;
  39.  
  40. int case_1_choice, case_2_choice, case_3_choice, case_4_choice;
  41. key = username + '.' + password;
  42.  
  43. current_money = 200;
  44.  
  45. while(ben == 1 && current_money > 0) {
  46. cout << menu_setup;
  47. cin >> opt;
  48.  
  49. switch(opt) {
  50. case 1:
  51. n1 = 1;
  52. inventory.open("txt/inventory.txt");
  53. if (inventory.is_open()) {
  54. while(!inventory.eof()) {
  55. getline(inventory,line);
  56. cout << n1 << ": " << line << "\n";
  57. n1 += 1;
  58. }
  59. } else {
  60. cout << "Somehow the inventory isn't open";
  61. }
  62. inventory.close();
  63.  
  64.  
  65. cout << "\nBuy\n" << divvy << "[Enter item]\n> ";
  66. cin >> case_1_choice;
  67. inv_source.open("txt/inv_source.txt");
  68. switch(case_1_choice) {
  69. case 1:
  70. search = "Father Azzarto Bobblehead";
  71. search1 = ":P";
  72. psearch = "=";
  73. psearch1 = ".";
  74.  
  75. size_t pos;
  76. size_t pos1;
  77. size_t price_initial;
  78. size_t price_final;
  79. while(inv_source.good()) {
  80. getline(inv_source,line); // get line from file
  81. cout << '*' << line;
  82. pos=line.find(search); // search
  83. cout << '$' << pos;
  84. pos1=line.find(search1);
  85. cout << '#' << pos1 << endl; // for loop concenation
  86. //cout << "pos=" << pos <<endl;
  87. for(pos ; pos < pos1; pos += 1) {
  88. getline(inv_source, line);
  89. buy_statement += line[pos];
  90. cout << "k="<<buy_statement << endl;
  91. }
  92.  
  93. }
  94. price_initial = line.find(psearch);
  95. price_initial += 1;
  96. price_final = line.find(psearch1);
  97. for(price_initial; price_initial < price_final; price_initial += 1) {
  98. price += line[price_initial];
  99. }
  100.  
  101. //price_int = stoi(price);
  102. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  103. cout << price_int;
  104. cart.open("txt/cart.txt");
  105.  
  106. cart << key << "~" << buy_statement << endl;
  107. //current_money -= price_int;
  108. cart.close();
  109. inv_source.close();
  110.  
  111. break;
  112. case 2:
  113. search = "Gloves";
  114. search1 = ":P";
  115. psearch = "=";
  116. psearch1 = "."; /*
  117.  
  118. size_t pos;
  119. size_t pos1;
  120. size_t price_initial;
  121. size_t price_final;
  122. */while(inv_source.good()) {
  123. getline(inv_source,line); // get line from file
  124. cout << '*' << line;
  125. pos=line.find(search); // search
  126. cout << '$' << pos;
  127. pos1=line.find(search1);
  128. cout << '#' << pos1 << endl; // for loop concenation
  129. //cout << "pos=" << pos <<endl;
  130. for(pos ; pos < pos1; pos += 1) {
  131. getline(inv_source, line);
  132. buy_statement += line[pos];
  133. cout << "k="<<buy_statement << endl;
  134. }
  135.  
  136. }
  137. price_initial = line.find(psearch);
  138. price_initial += 1;
  139. price_final = line.find(psearch1);
  140. for(price_initial; price_initial < price_final; price_initial += 1) {
  141. price += line[price_initial];
  142. }
  143.  
  144. //price_int = stoi(price);
  145. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  146. cout << price_int;
  147. cart.open("txt/cart.txt");
  148.  
  149. cart << key << "~" << buy_statement << endl;
  150. //current_money -= price_int;
  151. cart.close();
  152. inv_source.close();
  153. break;
  154. case 3:
  155. search = "Large Duffle Bag";
  156. search1 = ":P";
  157. psearch = "=";
  158. psearch1 = "."; /*
  159.  
  160. size_t pos;
  161. size_t pos1;
  162. size_t price_initial;
  163. size_t price_final;
  164. */while(inv_source.good()) {
  165. getline(inv_source,line); // get line from file
  166. cout << '*' << line;
  167. pos=line.find(search); // search
  168. cout << '$' << pos;
  169. pos1=line.find(search1);
  170. cout << '#' << pos1 << endl; // for loop concenation
  171. //cout << "pos=" << pos <<endl;
  172. for(pos ; pos < pos1; pos += 1) {
  173. getline(inv_source, line);
  174. buy_statement += line[pos];
  175. cout << "k="<<buy_statement << endl;
  176. }
  177.  
  178. }
  179. price_initial = line.find(psearch);
  180. price_initial += 1;
  181. price_final = line.find(psearch1);
  182. for(price_initial; price_initial < price_final; price_initial += 1) {
  183. price += line[price_initial];
  184. }
  185.  
  186. //price_int = stoi(price);
  187. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  188. cout << price_int;
  189. cart.open("txt/cart.txt");
  190.  
  191. cart << key << "~" << buy_statement << endl;
  192. //current_money -= price_int;
  193. cart.close();
  194. inv_source.close();
  195. break;
  196. case 4:
  197. search = "Winter Hat";
  198. search1 = ":P";
  199. psearch = "=";
  200. psearch1 = "."; /*
  201.  
  202. size_t pos;
  203. size_t pos1;
  204. size_t price_initial;
  205. size_t price_final;
  206. */while(inv_source.good()) {
  207. getline(inv_source,line); // get line from file
  208. cout << '*' << line;
  209. pos=line.find(search); // search
  210. cout << '$' << pos;
  211. pos1=line.find(search1);
  212. cout << '#' << pos1 << endl; // for loop concenation
  213. //cout << "pos=" << pos <<endl;
  214. for(pos ; pos < pos1; pos += 1) {
  215. getline(inv_source, line);
  216. buy_statement += line[pos];
  217. cout << "k="<<buy_statement << endl;
  218. }
  219.  
  220. }
  221. price_initial = line.find(psearch);
  222. price_initial += 1;
  223. price_final = line.find(psearch1);
  224. for(price_initial; price_initial < price_final; price_initial += 1) {
  225. price += line[price_initial];
  226. }
  227.  
  228. //price_int = stoi(price);
  229. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  230. cout << price_int;
  231. cart.open("txt/cart.txt");
  232.  
  233. cart << key << "~" << buy_statement << endl;
  234. //current_money -= price_int;
  235. cart.close();
  236. inv_source.close();
  237. cout << "";
  238. break;
  239. case 5:
  240. search = "Black Quilted Jacket";
  241. search1 = ":P";
  242. psearch = "=";
  243. psearch1 = "."; /*
  244.  
  245. size_t pos;
  246. size_t pos1;
  247. size_t price_initial;
  248. size_t price_final;
  249. */while(inv_source.good()) {
  250. getline(inv_source,line); // get line from file
  251. cout << '*' << line;
  252. pos=line.find(search); // search
  253. cout << '$' << pos;
  254. pos1=line.find(search1);
  255. cout << '#' << pos1 << endl; // for loop concenation
  256. //cout << "pos=" << pos <<endl;
  257. for(pos ; pos < pos1; pos += 1) {
  258. getline(inv_source, line);
  259. buy_statement += line[pos];
  260. cout << "k="<<buy_statement << endl;
  261. }
  262.  
  263. }
  264. price_initial = line.find(psearch);
  265. price_initial += 1;
  266. price_final = line.find(psearch1);
  267. for(price_initial; price_initial < price_final; price_initial += 1) {
  268. price += line[price_initial];
  269. }
  270.  
  271. //price_int = stoi(price);
  272. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  273. cout << price_int;
  274. cart.open("txt/cart.txt");
  275.  
  276. cart << key << "~" << buy_statement << endl;
  277. //current_money -= price_int;
  278. cart.close();
  279. inv_source.close();
  280. cout << "";
  281. break;
  282. case 6:
  283. search = "Varsity Sweater";
  284. search1 = ":P";
  285. psearch = "=";
  286. psearch1 = "."; /*
  287.  
  288. size_t pos;
  289. size_t pos1;
  290. size_t price_initial;
  291. size_t price_final;
  292. */while(inv_source.good()) {
  293. getline(inv_source,line); // get line from file
  294. cout << '*' << line;
  295. pos=line.find(search); // search
  296. cout << '$' << pos;
  297. pos1=line.find(search1);
  298. cout << '#' << pos1 << endl; // for loop concenation
  299. //cout << "pos=" << pos <<endl;
  300. for(pos ; pos < pos1; pos += 1) {
  301. getline(inv_source, line);
  302. buy_statement += line[pos];
  303. cout << "k="<<buy_statement << endl;
  304. }
  305.  
  306. }
  307. price_initial = line.find(psearch);
  308. price_initial += 1;
  309. price_final = line.find(psearch1);
  310. for(price_initial; price_initial < price_final; price_initial += 1) {
  311. price += line[price_initial];
  312. }
  313.  
  314. //price_int = stoi(price);
  315. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  316. cout << price_int;
  317. cart.open("txt/cart.txt");
  318.  
  319. cart << key << "~" << buy_statement << endl;
  320. //current_money -= price_int;
  321. cart.close();
  322. inv_source.close();
  323. cout << "";
  324. break;
  325. case 7:
  326. search = "Prep Socks";
  327. search1 = ":P";
  328. psearch = "=";
  329. psearch1 = "."; /*
  330.  
  331. size_t pos;
  332. size_t pos1;
  333. size_t price_initial;
  334. size_t price_final;
  335. */while(inv_source.good()) {
  336. getline(inv_source,line); // get line from file
  337. cout << '*' << line;
  338. pos=line.find(search); // search
  339. cout << '$' << pos;
  340. pos1=line.find(search1);
  341. cout << '#' << pos1 << endl; // for loop concenation
  342. //cout << "pos=" << pos <<endl;
  343. for(pos ; pos < pos1; pos += 1) {
  344. getline(inv_source, line);
  345. buy_statement += line[pos];
  346. cout << "k="<<buy_statement << endl;
  347. }
  348.  
  349. }
  350. price_initial = line.find(psearch);
  351. price_initial += 1;
  352. price_final = line.find(psearch1);
  353. for(price_initial; price_initial < price_final; price_initial += 1) {
  354. price += line[price_initial];
  355. }
  356.  
  357. //price_int = stoi(price);
  358. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  359. cout << price_int;
  360. cart.open("txt/cart.txt");
  361.  
  362. cart << key << "~" << buy_statement << endl;
  363. //current_money -= price_int;
  364. cart.close();
  365. inv_source.close();
  366. cout << "";
  367. break;
  368. case 8:
  369. search = "Tie Bar";
  370. search1 = ":P";
  371. psearch = "=";
  372. psearch1 = "."; /*
  373.  
  374. size_t pos;
  375. size_t pos1;
  376. size_t price_initial;
  377. size_t price_final;
  378. */while(inv_source.good()) {
  379. getline(inv_source,line); // get line from file
  380. cout << '*' << line;
  381. pos=line.find(search); // search
  382. cout << '$' << pos;
  383. pos1=line.find(search1);
  384. cout << '#' << pos1 << endl; // for loop concenation
  385. //cout << "pos=" << pos <<endl;
  386. for(pos ; pos < pos1; pos += 1) {
  387. getline(inv_source, line);
  388. buy_statement += line[pos];
  389. cout << "k="<<buy_statement << endl;
  390. }
  391.  
  392. }
  393. price_initial = line.find(psearch);
  394. price_initial += 1;
  395. price_final = line.find(psearch1);
  396. for(price_initial; price_initial < price_final; price_initial += 1) {
  397. price += line[price_initial];
  398. }
  399.  
  400. //price_int = stoi(price);
  401. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  402. cout << price_int;
  403. cart.open("txt/cart.txt");
  404.  
  405. cart << key << "~" << buy_statement << endl;
  406. //current_money -= price_int;
  407. cart.close();
  408. inv_source.close();
  409. cout << "";
  410. break;
  411. case 9:
  412. search = "Blue Prep Tie";
  413. search1 = ":P";
  414. psearch = "=";
  415. psearch1 = "."; /*
  416.  
  417. size_t pos;
  418. size_t pos1;
  419. size_t price_initial;
  420. size_t price_final;
  421. */while(inv_source.good()) {
  422. getline(inv_source,line); // get line from file
  423. cout << '*' << line;
  424. pos=line.find(search); // search
  425. cout << '$' << pos;
  426. pos1=line.find(search1);
  427. cout << '#' << pos1 << endl; // for loop concenation
  428. //cout << "pos=" << pos <<endl;
  429. for(pos ; pos < pos1; pos += 1) {
  430. getline(inv_source, line);
  431. buy_statement += line[pos];
  432. cout << "k="<<buy_statement << endl;
  433. }
  434.  
  435. }
  436. price_initial = line.find(psearch);
  437. price_initial += 1;
  438. price_final = line.find(psearch1);
  439. for(price_initial; price_initial < price_final; price_initial += 1) {
  440. price += line[price_initial];
  441. }
  442.  
  443. //price_int = stoi(price);
  444. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  445. cout << price_int;
  446. cart.open("txt/cart.txt");
  447.  
  448. cart << key << "~" << buy_statement << endl;
  449. //current_money -= price_int;
  450. cart.close();
  451. inv_source.close();
  452. cout << "";
  453. break;
  454. case 10:
  455. search = "SPP Belt";
  456. search1 = ":P";
  457. psearch = "=";
  458. psearch1 = "."; /*
  459.  
  460. size_t pos;
  461. size_t pos1;
  462. size_t price_initial;
  463. size_t price_final;
  464. */while(inv_source.good()) {
  465. getline(inv_source,line); // get line from file
  466. cout << '*' << line;
  467. pos=line.find(search); // search
  468. cout << '$' << pos;
  469. pos1=line.find(search1);
  470. cout << '#' << pos1 << endl; // for loop concenation
  471. //cout << "pos=" << pos <<endl;
  472. for(pos ; pos < pos1; pos += 1) {
  473. getline(inv_source, line);
  474. buy_statement += line[pos];
  475. cout << "k="<<buy_statement << endl;
  476. }
  477.  
  478. }
  479. price_initial = line.find(psearch);
  480. price_initial += 1;
  481. price_final = line.find(psearch1);
  482. for(price_initial; price_initial < price_final; price_initial += 1) {
  483. price += line[price_initial];
  484. }
  485.  
  486. //price_int = stoi(price);
  487. cout << "buy_statement = " <<buy_statement << endl; // +++FLAG ALERT
  488. cout << price_int;
  489. cart.open("txt/cart.txt");
  490.  
  491. cart << key << "~" << buy_statement << endl;
  492. //current_money -= price_int;
  493. cart.close();
  494. inv_source.close();
  495. cout << "";
  496. break;
  497. }
  498. /*
  499. cart.open("txt/cart.txt");
  500. if(cart.is_open()) {
  501. cout << "HERERERERERE";
  502. } else {
  503. cout << "cart file isn't open";
  504. }
  505. */
  506. //inv_source.close();
  507. //cart.close();
  508. break;
  509. case 2:
  510. cout << "\nReturn\n" << divvy << "[Enter item]\n>";
  511. cin >> case_2_choice;
  512.  
  513.  
  514. cart.open("txt/cart.txt");
  515. cart.close();
  516. break;
  517.  
  518. case 3:
  519. n4 = 1;
  520. cout << "\nList\n" << divvy;
  521. inventory.open("txt/inventory.txt");
  522. if (inventory.is_open()) {
  523. while(!inventory.eof()) {
  524. getline(inventory,line);
  525. cout << n4 << ": " << line << "\n";
  526. n4 += 1;
  527. }
  528. } else {
  529. cout << "Somehow the inventory isn't open";
  530. }
  531. inventory.close();
  532. break;
  533.  
  534. case 4:
  535. cout << "\nCart\n" << divvy;
  536. cart.open("txt/cart.txt"); // fsearch thing with the key {Username and password}
  537.  
  538.  
  539. cart.close();
  540. break;
  541.  
  542. case 5:
  543. cout << "\nQUIT\n" << divvy;// << "\n1.With items in cart\n2.Without any items\n>";
  544. ben -= 1;
  545. //cin >> case_4_choice;
  546. /*
  547. if(case_4_choice == 1) {
  548.  
  549. ben -= 1;
  550. } else if(case_4_choice == 2) {
  551. cout << "Arrivederci";
  552. ben -= 1;
  553.  
  554. }else{
  555. cout << "Hey, buddy what you doing my guy";
  556. }
  557. */
  558. break;
  559. default:
  560. cout << "Hey, hey buddy.";
  561. cout << "\n\n That's not an option\n\n\n\n\n\n\n\n";
  562. break;
  563. }
  564.  
  565.  
  566. }
  567. }
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578. // USERS ********************************************************
  579. void addNewMembers(string name, string encrypt) {
  580. // parameters are put to figure use variables in other functions of code
  581. string save;
  582. ofstream Users; // file stream
  583. Users.open("txt/Users.txt", ios::app);
  584. if(Users.is_open()) {
  585. Users << name << ':' << encrypt << '\n'; // appends to file called Users
  586. } else {
  587. cout << "Error with file opening";
  588. }
  589. Users.close();
  590. save = name + "." + encrypt;
  591.  
  592. menu(name, encrypt);
  593.  
  594. }
  595.  
  596. void algorithmNewUser(string ps, string name_of_user) {
  597. string hashnsalt; // acts sorta like a transitional function
  598.  
  599. reverse(ps.begin(),ps.end());
  600. hashnsalt = ps + "6" ;
  601. reverse(hashnsalt.begin(),hashnsalt.end());
  602. hashnsalt += "8";
  603. reverse(hashnsalt.begin(),hashnsalt.end());
  604.  
  605. // cout << hashnsalt << "\n"; #++++++++++++++++++ FLAG ALERT
  606. addNewMembers(name_of_user, hashnsalt);
  607. }
  608.  
  609. void newUser() {
  610. string username, password;
  611. cout << "Input a new username: ";
  612. cin >> username;
  613. while((4) != password.length()) { // if length != 4 then keep running
  614. cout << "Input a 4 number pin as a password: ";
  615. cin >> password;
  616. }
  617. algorithmNewUser(password, username);
  618. }
  619. //////////////////////////////////////// THE GREAT WALL OF USERS
  620.  
  621.  
  622. void welcomingReturningMember(string ps, string userName) { // welcomes returning user and also checks for username via password
  623. string username, key, line, save;
  624. int elseChoice;
  625. int j = 1; // it's the runner again
  626.  
  627. fstream Users;
  628.  
  629. key = userName + ":" + ps;
  630. Users.open("txt/Users.txt");
  631. if(Users.is_open()) {
  632.  
  633.  
  634.  
  635.  
  636. while (!Users.eof() && (j == 1)) {
  637. getline(Users,line);
  638. if(key == line) {
  639. cout << "Welcome back, " << userName << "!";
  640. break;
  641. }
  642. else {
  643. cout << "User not found\n";
  644. cout << "New Account?\n[Enter integer]\n1.Yes\n2.No\n>";
  645. cin >> elseChoice;
  646. switch(elseChoice) {
  647. case 1:
  648. j -= 1;
  649. newUser();
  650. break;
  651. case 2:
  652. j -= 1;
  653. cout << "Too bad, you are becoming a New Member\n\n";
  654. newUser();
  655. break;
  656. default:
  657. cout << "Okay well, that's not a choice";
  658. }
  659.  
  660. }
  661. }
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670. } else {
  671. cout << "File not working";
  672. }
  673. save = userName + "." + ps;
  674. menu(userName, ps);
  675. }
  676.  
  677. void returningUserAlgorithm(string pswd, string user) {
  678. string saltyhash; // just a standard decaration fam
  679. reverse(pswd.begin(),pswd.end()); // reverses the order
  680. saltyhash = pswd + "6";
  681. reverse(saltyhash.begin(),saltyhash.end());
  682. saltyhash += "8";
  683. reverse(saltyhash.begin(),saltyhash.end());// finishes the 6br8-Algoritm
  684.  
  685. welcomingReturningMember(saltyhash, user);
  686. }
  687.  
  688.  
  689.  
  690. void returningUser() {
  691. string username, password;
  692. cout << "Enter username: ";
  693. cin >> username;
  694.  
  695. while((4) != password.length()) {
  696. cout << "Enter password: ";
  697. cin >> password;
  698. }
  699. returningUserAlgorithm(password, username);
  700. }
  701.  
  702.  
  703. void user() {
  704. int user_choice, runner = 1;
  705. string user_prompt;
  706.  
  707. while(runner == 1) {
  708. user_prompt = "[Enter digit]\n1.New User\n2.Returning User\n>";
  709.  
  710. cout << user_prompt;
  711. cin >> user_choice;
  712. switch(user_choice) {
  713. case 1:
  714. runner -= 1;
  715. newUser();
  716. break;
  717. case 2:
  718. runner -= 1;
  719. returningUser();
  720. break;
  721. default:
  722. cout << "Not a valid choice";
  723. break;
  724. }
  725. }
  726.  
  727.  
  728. }
  729.  
  730. //
  731. void buyingMenu() {
  732. int runner = 1;
  733. char userChoice;
  734. while (runner == 1) {
  735. cout << "Inventory: ";
  736. cout << "1: Father Azzarto Bobblehead: 25 Tokens.\n";
  737. cout << "2: Gloves: 7 Tokens.\n";
  738. cout << "3: Large Duffle Bag: 30 Tokens.\n";
  739. cout << "4: Winter Had: 20 Tokens.\n";
  740. cout << "5: Black Quilted Jacket: 45 Tokens.\n";
  741. cout << "6: Varsity Sweater: 50 Tokens.\n";
  742. cout << "7: Prep Socks: 15 Tokens.\n";
  743. cout << "8: Tie Bar: 10 Tokens.\n";
  744. cout << "9: Blue Prep Tie: 30 Tokens.\n";
  745. cout << "10: SPP Belt: 25 Tokens.\n";
  746. cout << "\nSelect what item you want to buy [1-10]: \n";
  747. cin >> userChoice;
  748. switch(userChoice) {
  749. case 1:
  750. cout << "ur bad";
  751. break;
  752. } // switch statement
  753. } // while loop
  754. }
  755.  
  756.  
  757. // Lil God ########################################################
  758. int main() {
  759. cout << "Prep Campus Shop_V2" << "\n==========================\n";
  760. user();
  761.  
  762. return 0;
  763. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement