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 >
Wrap
C/C++ Source or Header
|
1993-05-07
|
4KB
|
84 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
/*-------------------------------------------------------------*\
| planets.C - 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 << "\n\n" << "All Planets: \n";
allPlanets.allElementsDo(showPlanet);
cout << "\n\n" << "Heavy Planets: \n";
heavyPlanets.allElementsDo(showPlanet);
cout << "\n\n" << "Bright Planets: \n";
brightPlanets.allElementsDo(showPlanet);
cout << "\n\n" << "Bright-or-Heavy Planets: \n";
brightPlanets.unionWith(heavyPlanets);
brightPlanets.allElementsDo(showPlanet);
cout << "\n\n"
<< "Did you notice that all these Sets are sorted"
<< " in the same order\n"
<< " (distance of planet from sun) ? \n";
return 0;
}