home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / PLANETS / PLANETS.CPP < prev    next >
Text File  |  1995-03-15  |  3KB  |  76 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. |  planets.CPP  -  All known planets are handled in a Sorted Set. |
  11. |                                                     """"""""""  |
  12. |     This example creates several sorted sets of planets.        |
  13. |     The sort order is based on each planets distance from       |
  14. |     the sun.                                                    |
  15. \*---------------------------------------------------------------*/
  16.  
  17.    #include <iostream.h>
  18.  
  19.                      // Let's use the Sorted Set Default Variant:
  20.    #include <isrtset.h>
  21.  
  22.                      // Get Class Planet:
  23.    #include "planet.h"
  24.  
  25.  
  26.  
  27.  int main()    {
  28.    ISortedSet<Planet>  allPlanets, heavyPlanets, brightPlanets;
  29.                        // A cursor to cursor through allPlanets:
  30.    ISortedSet<Planet>::Cursor aPCursor(allPlanets);
  31.  
  32.    SayPlanetName showPlanet;
  33.  
  34.    allPlanets.add( Planet("Earth",   149.60f,   1.0000f, 99.9f));
  35.    allPlanets.add( Planet("Jupiter", 778.3f,  317.818f,  -2.4f));
  36.    allPlanets.add( Planet("Mars",    227.9f,    0.1078f, -1.9f));
  37.    allPlanets.add( Planet("Mercury",  57.91f,   0.0558f, -0.2f));
  38.    allPlanets.add( Planet("Neptun", 4498.f,    17.216f,  +7.6f));
  39.    allPlanets.add( Planet("Pluto",  5910.f,     0.18f,  +14.7f));
  40.    allPlanets.add( Planet("Saturn", 1428.f,    95.112f,  +0.8f));
  41.    allPlanets.add( Planet("Uranus", 2872.f,    14.517f,  +5.8f));
  42.    allPlanets.add( Planet("Venus",   108.21f,   0.8148f, -4.1f));
  43.  
  44.  
  45.    forCursor(aPCursor)    {
  46.       if (allPlanets.elementAt(aPCursor).isHeavy())
  47.          heavyPlanets.add(allPlanets.elementAt(aPCursor));
  48.  
  49.       if (allPlanets.elementAt(aPCursor).isBright())
  50.          brightPlanets.add(allPlanets.elementAt(aPCursor));
  51.     }
  52.  
  53.     cout << endl << endl << "All Planets: " << endl;
  54.     allPlanets.allElementsDo(showPlanet);
  55.  
  56.     cout << endl << endl << "Heavy Planets: " << endl;
  57.     heavyPlanets.allElementsDo(showPlanet);
  58.  
  59.     cout << endl << endl << "Bright Planets: " << endl;
  60.     brightPlanets.allElementsDo(showPlanet);
  61.  
  62.     cout << endl << endl << "Bright-or-Heavy Planets: " << endl;
  63.     brightPlanets.unionWith(heavyPlanets);
  64.     brightPlanets.allElementsDo(showPlanet);
  65.  
  66.     cout << endl << endl
  67.          << "Did you notice that all these Sets are sorted"
  68.          << " in the same order"
  69.          << endl
  70.          << " (distance of planet from sun) ? " << endl;
  71.  
  72.     return 0;
  73.  
  74.  }
  75.  
  76.