home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / PHONLIST.H$ / PHONLIST
Encoding:
Text File  |  1991-12-11  |  1021 b   |  48 lines

  1. // PHONLIST.H
  2.  
  3. // This is an example class from Chapter 6 of the C++ Tutorial. This
  4. //     class demonstrates the use of friend classes. The PhoneList class
  5. //     stores an array of Records. The PhoneIter class acts as an
  6. //     iterator for a PhoneList, allowing you to move back and forth in
  7. //     the list.
  8.  
  9. #if !defined( _PHONLIST_H_ )
  10.  
  11. #define _PHONLIST_H_
  12.  
  13. struct Record
  14. {
  15.     char name[30];
  16.     char number[10];
  17. };
  18.  
  19. const int MAXLENGTH = 100;
  20.  
  21. class PhoneList
  22. {
  23. friend class PhoneIter;
  24. public:
  25.     PhoneList();
  26.     int add( const Record &newRec );
  27.     Record *search( const char *searchKey );
  28. private:
  29.     Record aray[MAXLENGTH];
  30.     int firstEmpty;          // First unused element
  31. };
  32.  
  33. class PhoneIter
  34. {
  35. public:
  36.     PhoneIter( PhoneList &m );
  37.     Record *getFirst();
  38.     Record *getLast();
  39.     Record *getNext();
  40.     Record *getPrev();
  41. private:
  42.     PhoneList *const mine;     // Constant pointer to PhoneList object
  43.     int currIndex;
  44. };
  45.  
  46. #endif  // _PHONLIST_H_
  47.  
  48.