home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / PHONLIST.CP$ / PHONLIST
Encoding:
Text File  |  1991-11-11  |  1.2 KB  |  68 lines

  1. // PHONLIST.CPP
  2.  
  3. #include "phonlist.h"
  4. #include <string.h>
  5.  
  6. PhoneList::PhoneList()
  7. {
  8.     firstEmpty = 0;
  9. }
  10.  
  11. int PhoneList::add( const Record &newRec )
  12. {
  13.     if( firstEmpty < MAXLENGTH - 1 )
  14.     {
  15.         aray[firstEmpty++] = newRec;
  16.         return 1;   // Indicate success
  17.     }
  18.     else return 0;
  19. }
  20.  
  21. Record *PhoneList::search( const char *searchKey )
  22. {
  23.     for( int i = 0; i < firstEmpty; i++ )
  24.         if( !strcmp( aray[i].name, searchKey ) )
  25.             return &aray[i];
  26.  
  27.     return 0;
  28. }
  29.  
  30. PhoneIter::PhoneIter( PhoneList &m )
  31.     : mine( &m )          // Initialize the constant member
  32. {
  33.     currIndex = 0;
  34. }
  35.  
  36. Record *PhoneIter::getFirst()
  37. {
  38.     currIndex = 0;
  39.     return &(mine->aray[currIndex]);
  40. }
  41.  
  42. Record *PhoneIter::getLast()
  43. {
  44.     currIndex = mine->firstEmpty - 1;
  45.     return &(mine->aray[currIndex]);
  46. }
  47.  
  48. Record *PhoneIter::getNext()
  49. {
  50.     if( currIndex < mine->firstEmpty - 1 )
  51.     {
  52.         currIndex++;
  53.         return &(mine->aray[currIndex]);
  54.     } 
  55.     else return 0;
  56. }
  57.  
  58. Record *PhoneIter::getPrev()
  59. {
  60.     if( currIndex > 0 )
  61.     {
  62.         currIndex--;
  63.         return &(mine->aray[currIndex]);
  64.     }
  65.     else return 0;
  66. }
  67.  
  68.