home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLCC / PLANET.H < prev    next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  62 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. /*-------------------------------------------------------------*\
  19. |  xsrtset.h  -  Class Planet for use in our Sorted Set example |
  20. \*-------------------------------------------------------------*/
  21.  
  22. class Planet   {
  23.  private:
  24.    char* plname;
  25.    float dist;
  26.    float mass;
  27.    float bright;
  28.  
  29.  public:
  30.      // Let's use the compiler generated default for
  31.      // the copy constructor
  32.  
  33.    Planet(char* aname, float adist, float amass, float abright) :
  34.      plname(aname), dist(adist),  mass(amass), bright(abright) {}
  35.  
  36.      // For any Set we need to provide element equality.
  37.    Boolean operator== (Planet const& aPlanet) const
  38.       { return plname == aPlanet.plname; }
  39.  
  40.      // For a Sorted Set we need to provide element comparision.
  41.    Boolean operator< (Planet const& aPlanet) const
  42.       { return dist < aPlanet.dist; }
  43.  
  44.    char*   name()     { return  plname; }
  45.  
  46.    Boolean isHeavy()  { return (mass   > 1.0); }
  47.    Boolean isBright() { return (bright < 0.0); }
  48. };
  49.  
  50.  
  51. /*-------------------------------------------------------------*\
  52. |   Iterator                                                    |
  53. \*-------------------------------------------------------------*/
  54. #include <iostream.h>
  55.  
  56. class SayPlanetName : public IIterator<Planet>   {
  57.  public:
  58.    virtual Boolean applyTo(Planet& p)
  59.          { cout << " " << p.name() << " "; return True;}
  60. };
  61.  
  62.