Advertisement
ninepintcoggie

Untitled

Mar 13th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <istream>
  4. #include <string>
  5. #include <ostream>
  6.  
  7. using namespace std;
  8.  
  9. ifstream contactlist;
  10.  
  11. void menu(string filename)
  12. {
  13. char choice;
  14. int count = 0;
  15. string firstname, lastname, address1, address2, email, number, giggles, search;
  16. string str = "";
  17. string next = "Next command?";
  18. contactlist.open(filename);
  19. cout << "Menu Options:" << endl << "1: Add contact" << endl << "2: Delete Contact" << endl
  20. << "3: Display All Contacts" << endl << "4: Search Contacts" << endl << "5: Create List" << endl << "6: End Program" << endl;
  21. cout << "Enter first choice twice. Sorry :/" << endl << "No spaces anywhere, please" << endl;
  22. cin >> choice;
  23. while (choice != '6')
  24. {
  25. cin >> choice;
  26. if (choice == '1') // create contact
  27. {
  28. cout << "Contact number " << count << endl;
  29. cout << "First name?" << endl;
  30. cin >> firstname;
  31. cout << "Last name?" << endl;
  32. cin >> lastname;
  33. cout << "First address line?" << endl;
  34. cin >> address1;
  35. cout << "Second address line?" << endl;
  36. cin >> address2;
  37. cout << "Phone number?" << endl;
  38. cin >> number;
  39. cout << "Email?" << endl;
  40. cin >> email;
  41. count++;
  42. cout << "Next command?" << endl;
  43. }
  44. else if (choice == '2') // delete
  45. {
  46. cout << "Delete contacts" << endl;
  47. cout << "Next command?" << endl;
  48. }
  49. else if (choice == '3') //display
  50. {
  51. while (getline(contactlist, giggles))
  52. {
  53. cout << "Shwoop!" << endl;
  54. }
  55. cout << "Next command?" << endl;
  56. }
  57. else if (choice == '4') // search
  58. {
  59. contactlist.open(filename);
  60. cout << "search contacts for a first or last name, street, phone number or email" << endl;
  61. cout << "Search input?" << endl;
  62. cin >> search;
  63. bool b(str == search);
  64. b = 0;
  65. while (contactlist >> str)
  66. {
  67.  
  68. if (b == 1)
  69. {
  70. cout << "Item found" << endl << str << endl;
  71. break;
  72. }
  73. else
  74. cout << "Item not present" << endl;
  75. }
  76. contactlist.close();
  77. cout << "Next command?" << endl;
  78. }
  79. else if (choice == '5') // create list
  80. {
  81. cout << "blerg" << endl;
  82. cout << "Next command?" << endl;
  83. }
  84. else if (choice == '6') // end and close program
  85. {
  86. cout << "Program closed" << endl;
  87. contactlist.close();
  88. cout << "Next command?" << endl;
  89. }
  90. else
  91. cout << "You tripped, hahahaha" << endl;
  92. }
  93. cout << "Next command?" << endl;
  94. }
  95.  
  96. int main()
  97. {
  98. char prompt;
  99. string filename;
  100. cout << "Name contact list filename" << endl;
  101. cin >> filename;
  102. filename += ".txt";
  103.  
  104. fstream contactlist(filename);
  105. if (contactlist.is_open())
  106. cout << "Contact list present" << endl;
  107. else
  108. {
  109. ofstream contactlist(filename);
  110. cout << "Contact list created" << endl;
  111. }
  112. cout << "Display menu?" << endl;
  113. cin >> prompt;
  114. if (prompt == 'y' || prompt == 'Y')
  115. menu(filename);
  116. else
  117. cout << "Your loss" << endl;
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement