home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / PLANETS / PLANET.H < prev    next >
Text File  |  1995-03-15  |  2KB  |  53 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9. /*-------------------------------------------------------------*\
  10. |  planet.h  -  Class Planet for use in our Sorted Set example  |
  11. \*-------------------------------------------------------------*/
  12.  
  13. class Planet   {
  14.  private:
  15.    char* plname;
  16.    float dist;
  17.    float mass;
  18.    float bright;
  19.  
  20.  public:
  21.      // Let's use the compiler generated default for
  22.      // the copy constructor
  23.  
  24.    Planet(char* aname, float adist, float amass, float abright) :
  25.      plname(aname), dist(adist),  mass(amass), bright(abright) {}
  26.  
  27.      // For any Set we need to provide element equality.
  28.    IBoolean operator== (Planet const& aPlanet) const
  29.       { return plname == aPlanet.plname; }
  30.  
  31.      // For a Sorted Set we need to provide element comparision.
  32.    IBoolean operator< (Planet const& aPlanet) const
  33.       { return dist < aPlanet.dist; }
  34.  
  35.    char*   name()     { return  plname; }
  36.  
  37.    IBoolean isHeavy()  { return (mass   > 1.0); }
  38.    IBoolean isBright() { return (bright < 0.0); }
  39. };
  40.  
  41.  
  42. /*-------------------------------------------------------------*\
  43. |   Iterator                                                    |
  44. \*-------------------------------------------------------------*/
  45. #include <iostream.h>
  46.  
  47. class SayPlanetName : public IIterator<Planet>   {
  48.  public:
  49.    virtual IBoolean applyTo(Planet& p)
  50.          { cout << " " << p.name() << " "; return True;}
  51. };
  52.  
  53.