home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxsamk / cocktail.c__ / COCKTAIL.C
Encoding:
C/C++ Source or Header  |  1992-10-26  |  1.8 KB  |  65 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2. #include <iset.h>
  3.  
  4. #include "cocktail.h"
  5. #include <iostream.h>
  6.  
  7. typedef ISet <Cocktail> Cocktails;
  8.  
  9. void listIngredients(Cocktails const&);
  10.  
  11. main() {
  12.     Cocktails cocktail;
  13.  
  14.     Cocktail TS("Tequila Sunrise");
  15.     TS.addIngredient(Ingredient("Tequila"));
  16.     TS.addIngredient(Ingredient("Grenadine Sirup"));
  17.     TS.addIngredient(Ingredient("Orange Juice"));
  18.     cocktail.add(TS);
  19.     Cocktail SD("Screw Driver");
  20.     SD.addIngredient(Ingredient("Wodka"));
  21.     SD.addIngredient(Ingredient("Orange Juice"));
  22.     cocktail.add(SD);
  23.     Cocktail BD("Bull Dog");
  24.     BD.addIngredient(Ingredient("Rum"));
  25.     BD.addIngredient(Ingredient("Wodka"));
  26.     BD.addIngredient(Ingredient("Bitter Lemon"));
  27.     cocktail.add(BD);
  28.     
  29.     listIngredients(cocktail);
  30.  
  31.     Cocktails::Cursor ctailcursor(cocktail);
  32.  
  33.     cocktail.locate(BD, ctailcursor);
  34.     cocktail.elementAt(ctailcursor).setMake(False); 
  35.     listIngredients(cocktail);
  36.  
  37.     cocktail.locate(BD,ctailcursor);
  38.     cocktail.elementAt(ctailcursor).setMake(True);
  39.     cocktail.locate(TS, ctailcursor);
  40.     cocktail.elementAt(ctailcursor).setMake(False);
  41.     listIngredients(cocktail);
  42.  
  43.     
  44.     return 0;
  45. }
  46.  
  47. void listIngredients(Cocktails const& cocktail) {
  48.     Cocktails::Cursor ctailcursor(cocktail);
  49.     IngSet neededIngredient;
  50.     IngSet::Cursor ingcursor(neededIngredient);
  51.     cout<<"\n\nTo make  : ";
  52.     for(ctailcursor.setToFirst(); ctailcursor.isValid(); ctailcursor.setToNext()) {
  53.         if (cocktail.elementAt(ctailcursor).getMake()) {
  54.             cout<<"   "<<cocktail.elementAt(ctailcursor).getName();
  55.             neededIngredient.unionWith(cocktail.elementAt(ctailcursor).getIngredients());
  56.         }
  57.     }
  58.     cout<<"\nyou need : ";
  59.     for (ingcursor.setToFirst(); ingcursor.isValid(); ingcursor.setToNext()) {
  60.         cout<<"   "<<neededIngredient.elementAt(ingcursor).getName();
  61.     }
  62.     cout<<"\n\n\n";
  63. }
  64.  
  65.