// L-5 MCS 360 Wed 1 Sep 2010 : phonebook.h

/* This file contains the header file with the prototypes
   of the member functions and data of the class PhoneBook. */

#ifndef PHONEBOOK_H
#define PHONEBOOK_H
#include<string>

class PhoneBook
{
   public:

      PhoneBook();
      /*
         Reads phone book entries from file.

         Precondition:
            file phonebook_data has valid entries.
         Postcondition:
            for PhoneBook b, there are b.length()
            entries b[k], with 0 <= k < b.length(). */

      ~PhoneBook();
      /*
         Deallocates memory occupied by entries.

         Postcondition:
            b.number = 0 after b.~PhoneBook(). */

      int length() const;
      /*
         Returns the number of entries in phone book.

         Precondition:
            constructor PhoneBook() executed correctly.
         Postcondition: length() >= 0. */

      std::string operator[](size_t k) const;
      /*
         Returns element at index k in phone book.

         Precondition: k < b.length() for PhoneBook b.
         Postcondition: 
            b[k] is k-th entry in phone book, 
            matching appropriate line on file. */

      void add(const std::string s);
      /*
         Adds a new entry defined by the data in s.

         Precondition:
            s matches the data format for file,
            contains phone number and name.
         Postcondition:
            after PhoneBook b; b[b.length()-1] == s. */

   private:

      int number;          // number of entries
      std::string *data;   // array of strings
};

#endif

