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

  1. // \EXAMPLES\EX0601.H
  2. // the prototype implementation of a phone book class
  3. //  class definition for phonebook example.
  4.  
  5. //  files in this example:
  6. // EX0601.H      this file -- definition of the class PhoneBk
  7. // %F,15,EX06021.CPP%EX06021.CPP   member functions of the class PhoneBk
  8. // %F,15,EX06022.CPP%EX06022.CPP   small application main() to exercise this class
  9.  
  10. #include <iostream.h>                // for stream I/O
  11. #include <string.h>                  // for string manipulation
  12.  
  13. // A typedef is used for strings rather than a string class
  14. // each name can be up to 19 characters plus a terminator
  15.  
  16. typedef char String[20];
  17.  
  18. // Definition of a class PhoneBk, each object is a phonebook.
  19. // Implentation has fixed sized arrays for names and phone numbers
  20. //   and an integer counter for the number of entries.
  21. // This is a variation of the phonebook example of Chapter 5.
  22. //   2 Constructors and a destructor have been added.
  23.  
  24. class PhoneBk {
  25.   String names[100];                 // room for 100 names
  26.   long tel[100];                     // room for 100 phone numbers
  27.   int numEntry;                      // number of entries so far
  28. public:
  29.   PhoneBk () { numEntry = 0; };      // default constructor
  30.   PhoneBk ( const PhoneBk& oldbook); // copy constructor
  31.   ~PhoneBk () {};                    // destructor
  32.   int insert( char* who, long telnum); // insert or change entry
  33.   int remove( char* who);            // remove entry for name
  34.   long lookup(char* who);            // look up number for name
  35.   ostream& print(ostream& os);       // print the phonebook
  36. };
  37.  
  38.