home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX08052.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  2.7 KB  |  75 lines

  1. // \EXAMPLES\EX08052.H
  2. //  class definitions for phonebook  list examples
  3. //--------------------------------------------------------------
  4.  
  5. //  files in this example:
  6. // %F,15,EX08051.H%EX08051.H       definition of class String
  7. // EX08052.H       this file
  8. // %F,15,EX08051.CPP%EX08051.CPP     member functions of String
  9. // %F,15,EX08052.CPP%EX08052.CPP     member functions of PhoneBk
  10. //              PhoneNum and List
  11. // %F,15,EX0805.CPP%EX0805.CPP   main() program
  12. //--------------------------------------------------------------
  13.  
  14. #ifndef PHLIST_H
  15. #define PHLIST_H
  16.  
  17. #include "EX08051.H"
  18.  
  19. //--------------------------------------------------------------
  20. // definition of a class PhoneNum,
  21. //     each object is a name and phone number
  22. //--------------------------------------------------------------
  23. class PhoneNum {
  24.   String name;
  25.   long tel;
  26. public:
  27.   PhoneNum() {};
  28.   PhoneNum( char* n, long tn ) : name (n), tel(tn) {};
  29.   ~PhoneNum() {};
  30.   void enter ( char* n, long tn );
  31.   void change ( long tn) { tel = tn; };
  32.   long gettel() { return tel; };
  33.   int compare (char* who) { return name.compare (who); };
  34.   void copy( const PhoneNum& entry);
  35.   ostream& print(ostream& os);
  36. };
  37.  
  38. //--------------------------------------------------------------
  39. // Definition of a class List,
  40. //     each object is a container of lists
  41. //--------------------------------------------------------------
  42. class List {
  43.   PhoneNum* list;
  44.   int last;
  45.   int current;
  46. public:
  47.   List(int maxsize = 100);          //  default size 100
  48.   ~List ();                         // destructor
  49.   PhoneNum* next();                 // iterator
  50.   void gototop();                   // reset iterator
  51.   void add(PhoneNum& entry);        // add an entry
  52.   void del();                       // delete current entry
  53. };
  54.  
  55. //--------------------------------------------------------------
  56. // Definition of a class PhoneBk, each object is a phonebook.
  57. //--------------------------------------------------------------
  58. class PhoneBk {
  59.   List list;
  60.   int maxsize;                       // maximum number of entries
  61.   int numEntry;                      // number of entries so far
  62. public:
  63.   PhoneBk ();                        // default constructor
  64.   PhoneBk ( const PhoneBk& oldbook); // copy constructor
  65.   ~PhoneBk () {};                    // destructor
  66.   int insert( char* who, long telnum); // insert or change entry
  67.   int remove( char* who);            // remove entry for name
  68.   long lookup(char* who);            // look up number for name
  69.   ostream& print(ostream& os);       // print the phonebook
  70. };
  71.  
  72. //--------------------------------------------------------------
  73. #endif
  74. //--------------------------------------------------------------
  75.