home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / planets / planets.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  3.5 KB  |  83 lines

  1. /**********************************************************************
  2. *                                                                     *
  3. *  IBM(R) VisualAge(TM) for C++ for Windows(R), Version 3.5           *
  4. *                                                                     *
  5. *  PID: 5622-880                                                      *
  6. *  - Licensed Material - Program-Property of IBM                      *
  7. *  (C) Copyright IBM Corp. 1991, 1995 - All Right Reserved.           *
  8. *                                                                     *
  9. *  US Government Users Restricted Rights - Use, duplication or        *
  10. *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  *
  11. *                                                                     *
  12. *  VisualAge, and IBM are trademarks or registered trademarks of      *
  13. *  International Business Machines Corporation.                       *
  14. *  Windows is a registered trademark of Microsoft Corporation.        *
  15. *                                                                     *
  16. **********************************************************************/
  17.  
  18. /*---------------------------------------------------------------*\
  19. |  planets.CPP  -  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 <iss.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.   forICursor (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 << endl << endl << "All Planets: " << endl;
  63.   allPlanets.allElementsDo (showPlanet);
  64.  
  65.   cout << endl << endl << "Heavy Planets: " << endl;
  66.   heavyPlanets.allElementsDo (showPlanet);
  67.  
  68.   cout << endl << endl << "Bright Planets: " << endl;
  69.   brightPlanets.allElementsDo (showPlanet);
  70.  
  71.   cout << endl << endl << "Bright-or-Heavy Planets: " << endl;
  72.   brightPlanets.unionWith (heavyPlanets);
  73.   brightPlanets.allElementsDo (showPlanet);
  74.  
  75.   cout << endl << endl
  76.        << "Did you notice that all these Sets are sorted"
  77.        << " in the same order"
  78.        << endl
  79.        << " (distance of planet from sun) ? " << endl;
  80.  
  81.   return 0;
  82. }
  83.