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

  1. // \EXAMPLES\EX0501.H
  2. // the prototype implementation of a phone book class
  3. //  class definition for phonebook example.
  4.  
  5. //--------------------------------------------------------------
  6. //  files in this example:
  7. // EX0501.H      this file -- definition of the class PhoneBk
  8. // %F,15,EX05011.CPP%EX05011.CPP   member functions of the class PhoneBk
  9. // %F,15,EX05012.CPP%EX05012.CPP   main() to exercise this PhoneBk
  10. //--------------------------------------------------------------
  11.  
  12. #include <iostream.h>                // for stream I/O
  13. #include <string.h>                  // for string manipulation
  14.  
  15. // A typedef is used for strings rather than a string class
  16. // each name can be up to 19 characters plus a terminator
  17.  
  18. typedef char String[20];
  19.  
  20. // Definition of a class PhoneBk, each object is a phonebook.
  21. // This program has fixed-sized arrays for names and phone
  22. //   numbers, and an integer counter for the number of entries.
  23. // This is a simple implementation of this class
  24. //   It does not have a constructor or destructor as these topics
  25. //   are not described in Teach Me C++ until Chapter 6.
  26.  
  27. class PhoneBk {
  28.   String names[100];                 // room for 100 names
  29.   long tel[100];                     // room for 100 numbers
  30.   int numEntry;                      // number of entries so far
  31. public:
  32.   void init() { numEntry = 0; };     // replace with constructor
  33.   int insert( char* who, long telnum); // insert or change entry
  34.   int remove( char* who);            // remove entry for name
  35.   long lookup(char* who);            // look up number for name
  36.   ostream& print(ostream& os);       // print the phonebook
  37. };
  38.  
  39.