home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
- #include <iset.h>
-
- #include "cocktail.h"
- #include <iostream.h>
-
- typedef ISet <Cocktail> Cocktails;
-
- void listIngredients(Cocktails const&);
-
- main() {
- Cocktails cocktail;
-
- Cocktail TS("Tequila Sunrise");
- TS.addIngredient(Ingredient("Tequila"));
- TS.addIngredient(Ingredient("Grenadine Sirup"));
- TS.addIngredient(Ingredient("Orange Juice"));
- cocktail.add(TS);
- Cocktail SD("Screw Driver");
- SD.addIngredient(Ingredient("Wodka"));
- SD.addIngredient(Ingredient("Orange Juice"));
- cocktail.add(SD);
- Cocktail BD("Bull Dog");
- BD.addIngredient(Ingredient("Rum"));
- BD.addIngredient(Ingredient("Wodka"));
- BD.addIngredient(Ingredient("Bitter Lemon"));
- cocktail.add(BD);
-
- listIngredients(cocktail);
-
- Cocktails::Cursor ctailcursor(cocktail);
-
- cocktail.locate(BD, ctailcursor);
- cocktail.elementAt(ctailcursor).setMake(False);
- listIngredients(cocktail);
-
- cocktail.locate(BD,ctailcursor);
- cocktail.elementAt(ctailcursor).setMake(True);
- cocktail.locate(TS, ctailcursor);
- cocktail.elementAt(ctailcursor).setMake(False);
- listIngredients(cocktail);
-
-
- return 0;
- }
-
- void listIngredients(Cocktails const& cocktail) {
- Cocktails::Cursor ctailcursor(cocktail);
- IngSet neededIngredient;
- IngSet::Cursor ingcursor(neededIngredient);
- cout<<"\n\nTo make : ";
- for(ctailcursor.setToFirst(); ctailcursor.isValid(); ctailcursor.setToNext()) {
- if (cocktail.elementAt(ctailcursor).getMake()) {
- cout<<" "<<cocktail.elementAt(ctailcursor).getName();
- neededIngredient.unionWith(cocktail.elementAt(ctailcursor).getIngredients());
- }
- }
- cout<<"\nyou need : ";
- for (ingcursor.setToFirst(); ingcursor.isValid(); ingcursor.setToNext()) {
- cout<<" "<<neededIngredient.elementAt(ingcursor).getName();
- }
- cout<<"\n\n\n";
- }
-