SHARE
TWEET

Untitled

a guest May 25th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. void writeNewContact() {
  7.     ofstream contact;
  8.     string name;
  9.     string number;
  10.     contact.open("Names.txt", std::ios_base::app);
  11.     cout << "Enter the name of new contact: ";
  12.     cin >> name;
  13.     cout << "\nEnter the number of " << name << ": ";
  14.     cin >> number;
  15.     cout << "Saved!" << endl;
  16.     system("cls");
  17.     contact.eof();
  18.     contact << name << endl;
  19.     contact.close();
  20.     contact.open("PhoneBook.txt", std::ios_base::app);
  21.     contact.eof();
  22.     contact << number << endl;
  23.     contact.close();
  24. }
  25. void getNumber(int num) {
  26.     num = num - 1;
  27.     ifstream example;
  28.     example.open("PhoneBook.txt");
  29.     string line;
  30.     for (int i = 0; !example.eof(); i++)
  31.     {
  32.         getline(example, line);
  33.         if (i == num)
  34.             cout << line << endl;
  35.     }
  36. }
  37. void getNames() {
  38.     int numberForName;
  39.     ifstream example;
  40.     example.open("Names.txt");
  41.     string line;
  42.     for (int i = 0; !example.eof(); i++)
  43.     {
  44.         getline(example, line);
  45.         cout << i + 1 << ") " << line << "; " << endl;
  46.     }
  47.     cin >> numberForName;
  48.     example.close();
  49.     getNumber(numberForName);
  50. }
  51. void menu() {
  52.     while (true) {
  53.         cout << "1) Look for number." << endl;
  54.         cout << "2) Add new number." << endl;
  55.         int menu;
  56.         cin >> menu;
  57.         system("cls");
  58.         switch (menu)
  59.         {
  60.         case 1:
  61.             getNames();
  62.             break;
  63.         case 2:
  64.             writeNewContact();
  65.             break;
  66.         default:
  67.             break;
  68.             cin >> menu;
  69.         }
  70.        
  71.         cout << "Do you wish to exit? " << endl;
  72.         string exit;
  73.         cin >> exit;
  74.         if (exit == "yes")
  75.             break;
  76.         else if (exit == "no")
  77.             continue;
  78.         system("cls");
  79.     }
  80. }
  81.  
  82. int main() {
  83.     menu();
  84.  
  85.  
  86.  
  87.     cin.get();
  88.     cin.get();
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top