// L-5 MCS 360 Mon 30 Aug 2010 : use_phonebook2.cpp

/* Below we illustrate the use of dynamic memory allocation and
   deallocation as a variation of the other program use_phonebook.cpp.

   A possible application could be to keep a backup copy of the
   phone book when we provide a delete operation. */

#include "phonebook.h"
#include<iostream>

using namespace std;

int main(int argc, char* argv[])
{
   PhoneBook *b;

   cout << "welcome to our phone book" << endl;
   cout << "reading data from file ..." << endl;

   b = new PhoneBook;

   int n = b->length();

   cout << "number of entries : " << n << endl;
   if(argc == 1)
      for(int k=0; k<n; k++)
         cout << "  entry " << k << " : " 
              << (*b)[k] << endl;
   else
   {
      string new_entry;

      cout << "give new entry : ";
      getline(cin,new_entry);

      b->add(new_entry);
   }

   b->~PhoneBook();

   return 0;
}

