Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.13 KB | None | 0 0
  1. /*
  2. * AUTHOR: Aaron redact
  3. *
  4. * CONTACT INFORMATION: aaronredact123@gmail.com
  5. *
  6. * CREATION DATE: November 16, 2017
  7. *
  8. * PROBLEM STATEMENT: Allow user to Save, Store, and Display a created address book.
  9. *
  10. * PROGRAM DESCRIPTION: Modularized program allows a user to save and store various information
  11. * about a person and save it to a seperate document. This allows the user
  12. * to close and reopen the program without losing their data. Menu driven.
  13. *
  14. * RUN INSTRUCTIONS: From the first menu you are given different options,
  15. * Get Data: Allows you to input a Name, Address, and Zip code for 1 person
  16. * Display: Displays all held data
  17. * Sort: Sorts data in one of 3 ways
  18. * Remove: Allows you to remove entries by 1 of 3 parameters
  19. * Find: Allows you to search for data by 1 of 3 parameters
  20. * Edit: Allows you to edit data on all paramters
  21. * Save: Saves data held in vectors to disk
  22. * Load: Loads files on disk to Vector
  23. * Makes sure when entering a name you use the formatting specified
  24. * To use a menu just type the letter between the brackets(A) (B) (C)
  25. * In sub menus there is 4 options
  26. * (N)ame, (Z)ip, (A)ddress, and (B)ack [to go back]
  27. */
  28. #include <iostream>
  29. #include <string>
  30. #include <sstream>
  31. #include <cstring>
  32. #include <cmath>
  33. #include <iomanip>
  34. #include <vector>
  35. #include <fstream>
  36. using namespace std;
  37. char MenuResponseFunction();
  38. void getInfo();
  39. void displayData();
  40. void sortData();
  41. void deleteData();
  42. void sortZip();
  43. void sortName();
  44. void sortAddress();
  45. void removeName();
  46. void removeZip();
  47. void removeAddress();
  48. void miniSort();
  49. void findData();
  50. void findName();
  51. void findAddress();
  52. void findZip();
  53. void editData();
  54. void editbyName();
  55. void editbyAddress();
  56. void editbyZip();
  57. void saveData();
  58. void loadData();
  59. void loadName();
  60. void loadAddress();
  61. void loadZip();
  62. ofstream fout; //allows for wring to and from files
  63. ifstream fin;
  64. const int MAX = 100; //Maximum number of data sets allowed
  65. vector <string> Names(MAX); //Vector holding name data
  66. vector <string> Address(MAX); //Vector holding Address data
  67. vector <string> ZipCode(MAX); //Vector holding Zip Codes
  68. int counter = 0; //Total number of data sets, starts at 1 instead of 0
  69. /*
  70. NAME: main()
  71. * TASK: Allows user to access various functions
  72. * through a switch driven menu
  73. * ACCEPTS: Accepts user defined Char from MenuResposeFunction().
  74. * RETURNS: Function based on user input
  75. * MODIFIES: none
  76. */
  77. int main(int argc, char *argv[]){
  78. bool run = true;
  79. do{
  80. switch (MenuResponseFunction()){ //Input from MenuResponseFunction()
  81. case 'G': getInfo(); break;
  82. case 'g': getInfo(); break;
  83. case 'D': displayData(); break;
  84. case 'd': displayData(); break;
  85. case 'S': sortData(); break;
  86. case 's': sortData(); break;
  87. case 'R': deleteData(); break;
  88. case 'r': deleteData(); break;
  89. case 'F': findData(); break;
  90. case 'f': findData(); break;
  91. case 'E': editData(); break;
  92. case 'e': editData(); break;
  93. case 'A': saveData(); break;
  94. case 'a': saveData(); break;
  95. case 'L': loadData(); break;
  96. case 'l': loadData(); break;
  97. case 'Q': run = false; break;
  98. case 'q': run = false; break;
  99. default : cout << "Invalid" << endl;
  100. }
  101. } while (run);
  102. cout << endl << "Program Terminated" << endl;
  103. system("pause");
  104. return 0;
  105. }
  106. /*
  107. * NAME: MenuResponseFunction()
  108. * TASK: Get user defined char for switch in main()
  109. * ACCEPTS: Accepts user input in form of Char
  110. * RETURNS: Char to main()
  111. * MODIFIES: None
  112. */
  113. char MenuResponseFunction(){
  114. char response; //Stores users response to menu
  115. cout << endl << "Please select an option" << endl
  116. << "(G)et Info, (D)isplay, (S)ort, (R)emove, (F)ind, (E)dit, s(A)ve, (L)oad, (Q)uit" << endl
  117. << "> ";
  118. cin >> response; //Passed to main()
  119. cin.ignore(256, '\n');
  120. return (response);
  121. }
  122. /*
  123. * NAME: getInfo()
  124. * TASK: Gets User defined data and stores to vector
  125. * ACCEPTS: Accepts user defined strings
  126. * RETURNS: Returns strings to global vectors
  127. * MODIFIES: Vectors Names, ZipCode, and Address. Increments counter
  128. */
  129. void getInfo(){
  130. string Name, Zip, AddressInfo; //Passed to Vectors after loop completes
  131. bool run = true; //Used to terminate while loop when needed
  132. char save, repeat; //Used for if loops that prompt user response
  133. while (run == true){ //Loop will get data sets until user terminates the loop
  134. cout << "(Firstname Lastname)";
  135. cout << endl << "Please insert a name: ";
  136. getline(cin,Name);
  137. cout << "Please insert an address: ";
  138. getline(cin,AddressInfo);
  139. cout << "Please insert a ZIP code: ";
  140. getline(cin,Zip);
  141. cout << endl << "Do you wish to save this data? <y/n>: ";
  142. cin >> save;
  143. if(toupper(save) == 'Y'){ //Confirms if user wishes to save data set
  144. counter++;
  145. string tmp, firstname, lastname; //Stores name data temporarily
  146. tmp = Name;
  147. ZipCode[counter] = Zip;
  148. Address[counter] = AddressInfo;
  149. int found; //Position of space in name;
  150. found=tmp.find(" ");
  151. lastname = tmp.substr (++found, 20);
  152. firstname = tmp.substr (0, --found);
  153. Names[counter] = lastname + ", " + firstname;
  154.  
  155. }
  156. cout << "Do you wish to add another data set? <y/n>: ";
  157. cin >> repeat;
  158. if(toupper(repeat) == 'N'){ //Confirms if user wishes to add a new data set
  159. run = false;
  160. }
  161. cin.clear(); //Clears cin buffer
  162. fflush(stdin);
  163. }
  164. }
  165. /*
  166. * NAME: displayData()
  167. * TASK: Displays stored data within vectors (Names, Address, ZipCode)
  168. * ACCEPTS: Accepts data stored in vectors
  169. * RETURNS: Returns displayed data to console
  170. * MODIFIES: None
  171. */
  172. void displayData(){
  173. for(int x=1; x<=counter; x++){
  174. if(Names[x] != ""){
  175. cout << "_______________________"
  176. << endl << Names[x]
  177. << endl << Address[x]
  178. << endl << ZipCode[x]
  179. << endl << "_______________________"
  180. << endl;
  181. }
  182. }
  183. }
  184. /*
  185. * NAME: sortData()
  186. * TASK: Prompts user to select from various sort methods
  187. * ACCEPTS: Accepts user input in form of Char
  188. * RETURNS: Returns call to sub sort function
  189. * MODIFIES: None
  190. */
  191. void sortData(){
  192. char sort; //Used to define sorting method
  193. bool run; //Used for sort menu
  194. cout << "Sort by (N)ame, (A)ddress, or (Z)ip? Go (B)ack?" << endl;
  195. cout << "> ";
  196. cin >> sort;
  197. do{
  198. switch(sort){
  199. case 'N': sortName(); break;
  200. case 'n': sortName(); break;
  201. case 'Z': sortZip(); break;
  202. case 'z': sortZip(); break;
  203. case 'A': sortAddress(); break;
  204. case 'a': sortAddress(); break;
  205. case 'B': run = false; break;
  206. case 'b': run = false; break;
  207. default: cout << "Invalid." << endl;
  208. }
  209. } while (run);
  210. }
  211. /*
  212. * NAME: sortAddress()
  213. * TASK: Sorts data by Address
  214. * ACCEPTS: Accepts none
  215. * RETURNS: Returns vector sorted by Address
  216. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  217. */
  218. void sortAddress(){
  219. for (int y=0; y<counter; y++){ //Sorts data by Address
  220. for (int z=1; z<counter; z++){
  221. if (Address[z] > Address[z+1]){
  222. swap(Names[z], Names[z+1]);
  223. swap(ZipCode[z], ZipCode[z+1]);
  224. swap(Address[z], Address[z+1]);
  225. }
  226. }
  227. }
  228. }
  229. /*
  230. * NAME: sortZip()
  231. * TASK: Sorts data by Zip code
  232. * ACCEPTS: Accepts none
  233. * RETURNS: Returns vector sorted by Zip code
  234. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  235. */
  236. void sortZip(){
  237. for (int y=0; y<counter; y++){ //Sorts data by Zip
  238. for (int z=1; z<counter; z++){
  239. if (ZipCode[z] > ZipCode[z+1]){
  240. swap(Names[z], Names[z+1]);
  241. swap(ZipCode[z], ZipCode[z+1]);
  242. swap(Address[z], Address[z+1]);
  243. }
  244. }
  245. }
  246. }
  247. /*
  248. * NAME: sortName()
  249. * TASK: Sorts data by last name
  250. * ACCEPTS: Accepts none
  251. * RETURNS: Returns vector sorted by last name
  252. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  253. */
  254. void sortName(){
  255. for (int y=0; y<counter; y++){ //Sorts data by last name
  256. for (int z=1; z<counter; z++){
  257. if (Names[z] > Names[z+1]){
  258. swap(Names[z], Names[z+1]);
  259. swap(ZipCode[z], ZipCode[z+1]);
  260. swap(Address[z], Address[z+1]);
  261. }
  262. }
  263. }
  264. }
  265. /*
  266. * NAME: deleteData()
  267. * TASK: Prompts user for removal method and calls function
  268. * ACCEPTS: User input to determine removal method
  269. * RETURNS: Call for sub removal function
  270. * MODIFIES: none
  271. */
  272. void deleteData(){
  273. char remove; //Used to define removal
  274. bool run; //Used for removal menu
  275. cout << "Remove by (N)ame, (A)ddress, or (Z)ip? Go (B)ack?" << endl;
  276. cout << "> ";
  277. cin >> remove;
  278. do{
  279. switch(remove){
  280. case 'N': removeName(); break;
  281. case 'n': removeName(); break;
  282. case 'Z': removeZip(); break;
  283. case 'z': removeZip(); break;
  284. case 'A': removeAddress(); break;
  285. case 'a': removeAddress(); break;
  286. case 'B': run = false; break;
  287. case 'b': run = false; break;
  288. default: cout << "Invalid." << endl;
  289. }
  290. } while (run);
  291. }
  292. /*
  293. * NAME: removeName()
  294. * TASK: Remove all files with user defined name
  295. * ACCEPTS: User input to determine removed name
  296. * RETURNS: List without defined name
  297. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  298. */
  299. void removeName(){
  300. string remove; //Name to be removed
  301. bool run = 0;
  302. cout << "Please insert the name you wish to remove" << endl
  303. << "(lastname, firstname)" << endl;
  304. cout << "> ";
  305. cin.clear(); //Clears cin buffer
  306. fflush(stdin);
  307. getline(cin,remove);
  308. for(int i=0;i<=counter;i++){ //Searches for name to be removed
  309. if(remove==Names[i]){
  310. cout << Names[i] << " Removed!" << endl;
  311. Names[i] = "";
  312. ZipCode[i] = "";
  313. Address[i] = "";
  314. run = 1;
  315. }
  316. }
  317. if(run == 0){
  318. cout << remove << " Not found" << endl;
  319. }
  320. miniSort(); //Pushes blank data to back
  321. }
  322. /*
  323. * NAME: removeZip()
  324. * TASK: Remove all files with user defined Zip Code
  325. * ACCEPTS: User input to determine removed Zip Code
  326. * RETURNS: List without defined Zip Codes
  327. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  328. */
  329. void removeZip(){
  330. string remove; //Zip to be removed
  331. bool run = 0;
  332. cout << "Please insert the Zip Code you wish to remove" << endl;
  333. cout << "> ";
  334. cin.clear(); //Clears cin buffer
  335. fflush(stdin);
  336. getline(cin,remove);
  337. for(int i=0;i<=counter;i++){ //Searches for name to be removed
  338. if(remove==ZipCode[i]){
  339. cout << ZipCode[i] << " Removed!" << endl;
  340. Names[i] = "";
  341. ZipCode[i] = "";
  342. Address[i] = "";
  343. run = 1;
  344. }
  345. }
  346. if(run == 0){
  347. cout << remove << " Not found" << endl;
  348. }
  349. void miniSort(); //Pushes blank data to back
  350. }
  351. /*
  352. * NAME: removeAddress()
  353. * TASK: Remove all files with user defined Address
  354. * ACCEPTS: User input to determine removed Addresses
  355. * RETURNS: List without defined Addresses
  356. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  357. */
  358. void removeAddress(){
  359. string remove; //Address to be removed
  360. bool run = 0;
  361. cout << "Please insert the Address you wish to remove" << endl;
  362. cout << "> ";
  363. cin.clear(); //Clears cin buffer
  364. fflush(stdin);
  365. getline(cin,remove);
  366. for(int i=0;i<=counter;i++){ //Searches for name to be removed
  367. if(remove==Address[i]){
  368. cout << Address[i] << " Removed!" << endl;
  369. Names[i] = "";
  370. ZipCode[i] = "";
  371. Address[i] = "";
  372. run = 1;
  373. }
  374. }
  375. if(run == 0){
  376. cout << remove << " Not found" << endl;
  377. }
  378. void miniSort(); //Pushes blank data to back
  379. }
  380. /*
  381. * NAME: miniSort()
  382. * TASK: Push blank strings to end of vector
  383. * ACCEPTS: None
  384. * RETURNS: Sorted Vectors
  385. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  386. */
  387. void miniSort(){
  388. for (int y=0; y<counter; y++){//Runs through vector multiple times to find blank strings
  389. for (int z=1; z<counter; z++){
  390. if (Names[z] == ""){
  391. swap(Names[z], Names[z+1]);
  392. swap(ZipCode[z], ZipCode[z+1]);
  393. swap(Address[z], Address[z+1]);
  394. }
  395. }
  396. }
  397. }
  398. /*
  399. * NAME: findData()
  400. * TASK: Prompts user for search method
  401. * ACCEPTS: User input in form of string
  402. * RETURNS: Sub search function
  403. * MODIFIES: None
  404. */
  405. void findData(){
  406. char find; //Used to define search
  407. bool run; //Used for removal menu
  408. cout << "Search by (N)ame, (A)ddress, or (Z)ip? Go (B)ack?" << endl;
  409. cout << "> ";
  410. cin >> find;
  411. do{
  412. switch(find){
  413. case 'N': findName(); break;
  414. case 'n': findName(); break;
  415. case 'Z': findZip(); break;
  416. case 'z': findZip(); break;
  417. case 'A': findAddress(); break;
  418. case 'a': findAddress(); break;
  419. case 'B': run = false; break;
  420. case 'b': run = false; break;
  421. default: cout << "Invalid." << endl;
  422. }
  423. } while (run);
  424. }
  425. /*
  426. * NAME: findName()
  427. * TASK: Searches vectors for specified Name
  428. * ACCEPTS: User input to define searched vector
  429. * RETURNS: Requested data to console
  430. * MODIFIES: None
  431. */
  432. void findName(){
  433. string search;
  434. bool b = 0;
  435. cout << "Please input a name" << endl
  436. << "(lastname, firstname)" << endl;
  437. cout << "> ";
  438. cin.clear(); //Clears cin buffer
  439. fflush(stdin);
  440. getline(cin,search);
  441. cout << "Searching. . . " << endl;
  442. for(int i=0;i<=counter;i++){
  443. if(search==Names[i]){
  444. cout << "Found in Postion: " << i << endl;
  445. cout << "_______________________"
  446. << endl << Names[i]
  447. << endl << Address[i]
  448. << endl << ZipCode[i]
  449. << endl << "_______________________"
  450. << endl;
  451. b = 1;
  452. }
  453. }
  454. if(b == 0){
  455. cout << search << " Not found" << endl;
  456. }
  457. cout << "Search Complete" << endl;
  458. }
  459. /*
  460. * NAME: findZip()
  461. * TASK: Searches vectors for specified Zip Code
  462. * ACCEPTS: User input to define searched vector
  463. * RETURNS: Requested data to console
  464. * MODIFIES: None
  465. */
  466. void findZip(){
  467. string search;
  468. bool b = 0;
  469. cout << "Please input a Zip Code" << endl;
  470. cout << "> ";
  471. cin.clear(); //Clears cin buffer
  472. fflush(stdin);
  473. getline(cin,search);
  474. cout << "Searching. . . " << endl;
  475. for(int i=0;i<=counter;i++){
  476. if(search==ZipCode[i]){
  477. cout << "Found in Postion: " << i << endl;
  478. cout << "_______________________"
  479. << endl << Names[i]
  480. << endl << Address[i]
  481. << endl << ZipCode[i]
  482. << endl << "_______________________"
  483. << endl;
  484. b = 1;
  485. }
  486. }
  487. if(b == 0){
  488. cout << search << " Not found" << endl;
  489. }
  490. cout << "Search Complete" << endl;
  491. }
  492. /*
  493. * NAME: findAddress()
  494. * TASK: Searches vectors for specified Address
  495. * ACCEPTS: User input to define searched vector
  496. * RETURNS: Requested data to console
  497. * MODIFIES: None
  498. */
  499. void findAddress(){
  500. string search;
  501. bool b = 0;
  502. cout << "Please input an Address" << endl;
  503. cout << "> ";
  504. cin.clear(); //Clears cin buffer
  505. fflush(stdin);
  506. getline(cin,search);
  507. cout << "Searching. . . " << endl;
  508. for(int i=0;i<=counter;i++){
  509. if(search==Address[i]){
  510. cout << "Found in Postion: " << i << endl;
  511. cout << "_______________________"
  512. << endl << Names[i]
  513. << endl << Address[i]
  514. << endl << ZipCode[i]
  515. << endl << "_______________________"
  516. << endl;
  517. b = 1;
  518. }
  519. }
  520. if(b == 0){
  521. cout << search << " Not found" << endl;
  522. }
  523. cout << "Search Complete" << endl;
  524. }
  525. /*
  526. * NAME: editData()
  527. * TASK: Searches vectors for specified data, prompts user to edit
  528. * ACCEPTS: User input to define searched vector
  529. * RETURNS: Requested data to console
  530. * MODIFIES: All data stored in vectors (Names, Address, ZipCode)
  531. */
  532. void editData(){
  533. char edit; //Used to define edit
  534. bool run; //Used for removal menu
  535. cout << "Edit by (N)ame, (A)ddress, or (Z)ip? Go (B)ack?" << endl;
  536. cout << "> ";
  537. cin >> edit;
  538. do{
  539. switch(edit){
  540. case 'N': editbyName(); break;
  541. case 'n': editbyName(); break;
  542. case 'Z': editbyZip(); break;
  543. case 'z': editbyZip(); break;
  544. case 'A': editbyAddress(); break;
  545. case 'a': editbyAddress(); break;
  546. case 'B': run = false; break;
  547. case 'b': run = false; break;
  548. default: cout << "Invalid." << endl;
  549. }
  550. } while (run);
  551. }
  552. /*
  553. * NAME: editbyName()
  554. * TASK: Searches vectors for specified Name to be edited
  555. * ACCEPTS: User input to define searched vector
  556. * RETURNS: Requested data to console to be edited
  557. * MODIFIES: All Names stored in vectors (Names)
  558. */
  559. void editbyName(){
  560. string search;//Used to search for specified data
  561. bool b = 0;
  562. cout << "Please input a name" << endl
  563. << "(lastname, firstname)" << endl;
  564. cout << "> ";
  565. cin.clear(); //Clears cin buffer
  566. fflush(stdin);
  567. getline(cin,search);
  568. cout << endl;
  569. for(int i=0;i<=counter;i++){
  570. if(search==Names[i]){
  571. string Name;
  572. char save; //Used to confirm change in data
  573. cout << "Found in Postion: " << i << endl;
  574. cout << "(Firstname Lastname)";
  575. cout << endl << "Please insert a name: ";
  576. getline(cin,Name);
  577. cout << endl << "Do you wish to save this data? <y/n>: ";
  578. cin >> save;
  579. if(toupper(save) == 'Y'){ //Confirms if user wishes to save data set
  580. string tmp, firstname, lastname; //Stores name data temporarily
  581. tmp = Name;
  582. int found; //Position of space in name;
  583. found=tmp.find(" ");
  584. lastname = tmp.substr (++found, 20);
  585. firstname = tmp.substr (0, --found);
  586. Names[i] = lastname + ", " + firstname;
  587. b = 1;
  588. }
  589. }
  590. }
  591. if(b == 0){
  592. cout << search << " Not found" << endl;
  593. }
  594. cout << "Search Complete" << endl;
  595. cin.clear(); //Clears cin buffer
  596. fflush(stdin);
  597. }
  598. /*
  599. * NAME: editbyZip()
  600. * TASK: Searches vectors for specified ZIPCODE to be edited
  601. * ACCEPTS: User input to define searched vector
  602. * RETURNS: Requested data to console to be edited
  603. * MODIFIES: All ZipCodes stored in vectors (ZipCode)
  604. */
  605. void editbyZip(){
  606. string search;//Used to search for specified data
  607. bool b = 0;
  608. cout << "Please input a Zip Code" << endl;
  609. cout << "> ";
  610. cin.clear(); //Clears cin buffer
  611. fflush(stdin);
  612. getline(cin,search);
  613. cout << endl;
  614. for(int i=0;i<=counter;i++){
  615. if(search==ZipCode[i]){
  616. string Zip;
  617. char save; //Used to confirm change in data
  618. cout << "Found in Postion: " << i << endl;
  619. cout << endl << "Please insert a ZipCode: ";
  620. getline(cin,Zip);
  621. cout << endl << "Do you wish to save this data? <y/n>: ";
  622. cin >> save;
  623. if(toupper(save) == 'Y'){ //Confirms if user wishes to save data set
  624. ZipCode[i] = Zip;
  625. b = 1;
  626. }
  627. }
  628. }
  629. if(b == 0){
  630. cout << search << " Not found" << endl;
  631. }
  632. cout << "Search Complete" << endl;
  633. cin.clear(); //Clears cin buffer
  634. fflush(stdin);
  635. }
  636. /*
  637. * NAME: editbyAddress()
  638. * TASK: Searches vectors for specified Address to be edited
  639. * ACCEPTS: User input to define searched vector
  640. * RETURNS: Requested data to console to be edited
  641. * MODIFIES: All Addresses stored in vectors (ZipCode)
  642. */
  643. void editbyAddress(){
  644. string search; //Used to search for specified data
  645. bool b = 0;
  646. cout << "Please input an Address" << endl;
  647. cout << "> ";
  648. cin.clear(); //Clears cin buffer
  649. fflush(stdin);
  650. getline(cin,search);
  651. cout << endl;
  652. for(int i=0;i<=counter;i++){
  653. if(search==Address[i]){
  654. string Addressdata;
  655. char save; //Used to confirm change in data
  656. cout << "Found in Postion: " << i << endl;
  657. cout << endl << "Please insert an Address: ";
  658. getline(cin,Addressdata);
  659. cout << endl << "Do you wish to save this data? <y/n>: ";
  660. cin >> save;
  661. if(toupper(save) == 'Y'){ //Confirms if user wishes to save data set
  662. Address[i] = Addressdata;
  663. b = 1;
  664. }
  665. }
  666. }
  667. if(b == 0){
  668. cout << search << " Not found" << endl;
  669. }
  670. cout << "Search Complete" << endl;
  671. cin.clear(); //Clears cin buffer
  672. fflush(stdin);
  673. }
  674. /*
  675. * NAME: saveData()
  676. * TASK: Saves data to external file
  677. * ACCEPTS: All vectors used to store data to write to file
  678. * RETURNS: Files created to program folder
  679. * MODIFIES: None
  680. */
  681. void saveData(){
  682. fout.open("Names.txt", ios::app); //Creates/Opens file to be saved to
  683. for(int x=1; x<=counter; x++){
  684. fout << Names[x] << endl;
  685. }
  686. fout.close();
  687. fout.open("ZIP.txt", ios::app); //Creates/Opens file to be saved to
  688. for(int x=1; x<=counter; x++){
  689. fout << ZipCode[x] << endl;
  690. }
  691. fout.close();
  692. fout.open("Address.txt", ios::app); //Creates/Opens file to be saved to
  693. for(int x=1; x<=counter; x++){
  694. fout << Address[x] << endl;
  695. }
  696. fout.close();
  697. cout << "Save complete!";
  698. }
  699. /*
  700. * NAME: loadData()
  701. * TASK: loads data from external files
  702. * ACCEPTS: external data in form of text files
  703. * RETURNS: data from files to Zip, name, and address vectors
  704. * MODIFIES: Vectors used to store data
  705. */
  706. void loadData(){
  707. loadName();
  708. loadAddress();
  709. loadZip();
  710. }
  711. /*
  712. * NAME: loadName()
  713. * TASK: loads data from Names.txt
  714. * ACCEPTS: external data in form of text files
  715. * RETURNS: data from files to Names vector
  716. * MODIFIES: Vectors used to store data
  717. */
  718. void loadName(){
  719. int pointer; //holds size of file
  720. fin.open("Names.txt", ios::app);
  721. if (fin.fail()) {
  722. cerr << "could not open intput file names.txt" << endl;
  723. system("pause");
  724. exit(1);
  725. }
  726. pointer++;
  727. getline(fin,Names[pointer]);
  728. for(int ndx = 0; !fin.eof(); ndx++){
  729. pointer++;
  730. getline(fin,Names[pointer]);
  731. }
  732. fin.close();
  733. counter = pointer;
  734. }
  735. /*
  736. * NAME: loadAddress()
  737. * TASK: loads data from Address.txt
  738. * ACCEPTS: external data in form of text files
  739. * RETURNS: data from files to Address vector
  740. * MODIFIES: Vectors used to store data
  741. */
  742. void loadAddress(){
  743. int pointer; //holds size of file
  744. fin.open("Address.txt", ios::app);
  745. if (fin.fail()) {
  746. cerr << "could not open intput file names.txt" << endl;
  747. system("pause");
  748. exit(1);
  749. }
  750. pointer++;
  751. getline(fin,Address[pointer]);
  752. for(int ndx = 0; !fin.eof(); ndx++){
  753. pointer++;
  754. getline(fin,Address[pointer]);
  755. }
  756. fin.close();
  757. }
  758. /*
  759. * NAME: loadZip()
  760. * TASK: loads data from ZIP.txt
  761. * ACCEPTS: external data in form of text files
  762. * RETURNS: data from files to ZipCode vector
  763. * MODIFIES: Vectors used to store data
  764. */
  765. void loadZip(){
  766. int pointer; //holds size of file
  767. fin.open("ZIP.txt", ios::app);
  768. if (fin.fail()) {
  769. cerr << "could not open intput file names.txt" << endl;
  770. system("pause");
  771. exit(1);
  772. }
  773. pointer++;
  774. getline(fin,Address[pointer]);
  775. for(int ndx = 0; !fin.eof(); ndx++){
  776. pointer++;
  777. getline(fin,ZipCode[pointer]);
  778. }
  779. fin.close();
  780. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement