home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / TUTORIAL / ICLCC / TUTOR5 / KPERSON.H < prev    next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  55 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /* COPYRIGHT:                                                                 */
  4. /* ----------                                                                 */
  5. /* Copyright (C) International Business Machines Corp., 1991,1992.            */
  6. /*                                                                            */
  7. /* DISCLAIMER OF WARRANTIES:                                                  */
  8. /* -------------------------                                                  */
  9. /* The following [enclosed] code is sample code created by IBM                */
  10. /* Corporation.  This sample code is not part of any standard IBM product     */
  11. /* and is provided to you solely for the purpose of assisting you in the      */
  12. /* development of your applications.  The code is provided "AS IS",           */
  13. /* without warranty of any kind.  IBM shall not be liable for any damages     */
  14. /* arising out of your use of the sample code, even if they have been         */
  15. /* advised of the possibility of such damages.                                */
  16. /*                                                                            */
  17. /******************************************************************************/
  18. #include <tstring.h>
  19. #include <iglobals.h>
  20.  
  21. class Person {
  22.         String name;                          // the key
  23.         String telephoneNumber;
  24. public:
  25.         Person(char* n, char* tel) : name(n), telephoneNumber(tel)  { }
  26.         Person(Person const & person) : name(person.name),
  27.                                            telephoneNumber(person.telephoneNumber)  { }
  28.         Person& operator = (Person const & person) {
  29.            if (& person != this) {
  30.               name = person.name;
  31.               telephoneNumber =person.telephoneNumber;
  32.            } /* endif */
  33.           return *this;
  34.         }
  35.  
  36.         String const& getName()  const {
  37.              return name;
  38.         }
  39.         String const& getTel() const{
  40.              return telephoneNumber;
  41.         }
  42.         String const & getKey() const {
  43.              return telephoneNumber;
  44.         }
  45. };
  46. // key function
  47.  
  48. inline String const &  key  (Person const & keyPerson){
  49.       return   keyPerson.getName();
  50. }
  51. // hash function for the key
  52. .....................  hash (.................., ...............){
  53.       return  hash ( ............., . );     // hash for char * defined in istdops.h
  54. }
  55.