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 >
Wrap
Text File
|
1995-03-15
|
3KB
|
76 lines
/*************************************************************************
IBM C/C++ Tools Version 3.00 - Collection Class Library
(C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
IBM. All Rights Reserved. US Government Users Restricted Rights - Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
*************************************************************************/
/*---------------------------------------------------------------*\
| planets.CPP - All known planets are handled in a Sorted Set. |
| """""""""" |
| This example creates several sorted sets of planets. |
| The sort order is based on each planets distance from |
| the sun. |
\*---------------------------------------------------------------*/
#include <iostream.h>
// Let's use the Sorted Set Default Variant:
#include <isrtset.h>
// Get Class Planet:
#include "planet.h"
int main() {
ISortedSet<Planet> allPlanets, heavyPlanets, brightPlanets;
// A cursor to cursor through allPlanets:
ISortedSet<Planet>::Cursor aPCursor(allPlanets);
SayPlanetName showPlanet;
allPlanets.add( Planet("Earth", 149.60f, 1.0000f, 99.9f));
allPlanets.add( Planet("Jupiter", 778.3f, 317.818f, -2.4f));
allPlanets.add( Planet("Mars", 227.9f, 0.1078f, -1.9f));
allPlanets.add( Planet("Mercury", 57.91f, 0.0558f, -0.2f));
allPlanets.add( Planet("Neptun", 4498.f, 17.216f, +7.6f));
allPlanets.add( Planet("Pluto", 5910.f, 0.18f, +14.7f));
allPlanets.add( Planet("Saturn", 1428.f, 95.112f, +0.8f));
allPlanets.add( Planet("Uranus", 2872.f, 14.517f, +5.8f));
allPlanets.add( Planet("Venus", 108.21f, 0.8148f, -4.1f));
forCursor(aPCursor) {
if (allPlanets.elementAt(aPCursor).isHeavy())
heavyPlanets.add(allPlanets.elementAt(aPCursor));
if (allPlanets.elementAt(aPCursor).isBright())
brightPlanets.add(allPlanets.elementAt(aPCursor));
}
cout << endl << endl << "All Planets: " << endl;
allPlanets.allElementsDo(showPlanet);
cout << endl << endl << "Heavy Planets: " << endl;
heavyPlanets.allElementsDo(showPlanet);
cout << endl << endl << "Bright Planets: " << endl;
brightPlanets.allElementsDo(showPlanet);
cout << endl << endl << "Bright-or-Heavy Planets: " << endl;
brightPlanets.unionWith(heavyPlanets);
brightPlanets.allElementsDo(showPlanet);
cout << endl << endl
<< "Did you notice that all these Sets are sorted"
<< " in the same order"
<< endl
<< " (distance of planet from sun) ? " << endl;
return 0;
}