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