#include #include "recipe.h" #include "kitchen.h" // Helper functions void readRecipe(istream &istr, ostream &ostr, list &recipes); void addIngredients(istream &istr, ostream &ostr, Kitchen &kitchen); void printRecipe(istream &istr, ostream &ostr, list &recipes); void makeRecipe(istream &istr, ostream &ostr, list &recipes, Kitchen &kitchen); // The main loop parses opens the files for I/O & parses the input int main(int argc, char* argv[]) { // Check the number of arguments. if (argc != 3) { cerr << "Usage: " << argv[0] << " in-file out-file\n"; return 1; } // Open and test the input file. ifstream istr(argv[1]); if (!istr) { cerr << "Could not open " << argv[1] << " to read\n"; return 1; } // Open and test the output file. ofstream ostr(argv[2]); if (!ostr) { cerr << "Could not open " << argv[2] << " to write\n"; return 1; } // the kitchen & recipe list Kitchen kitchen; list recipes; // some variables to help with parsing char c; while (istr >> c) { if (c == 'r') { // READ A NEW RECIPE readRecipe(istr,ostr,recipes); } else if (c == 'a') { // ADD INGREDIENTS TO THE KITCHEN addIngredients(istr,ostr,kitchen); } else if (c == 'p') { // PRINT A PARTICULAR RECIPE printRecipe(istr,ostr,recipes); } else if (c == 'm') { // MAKE SOME FOOD makeRecipe(istr,ostr,recipes,kitchen); } else if (c == 'k') { // PRINT THE CONTENTS OF THE KITCHEN kitchen.printIngredients(ostr); } else { cerr << "unknown character: " << c << endl; exit(0); } } } void readRecipe(istream &istr, ostream &ostr, list &recipes) { int units; string name, name2; istr >> name; // build the new recipe Recipe r(name); while (1) { istr >> units; if (units == 0) break; assert (units > 0); istr >> name2; r.addIngredient(name2,units); } // add it to the list recipes.push_back(r); ostr << "Recipe for " << name << " added" << endl; } void addIngredients(istream &istr, ostream &ostr, Kitchen &kitchen) { int units; string name; int count = 0; while (1) { istr >> units; if (units == 0) break; assert (units > 0); istr >> name; // add the ingredients to the kitchen kitchen.addIngredient(name,units); count++; } ostr << count << " ingredients added to kitchen" << endl; } void printRecipe(istream &istr, ostream &ostr, list &recipes) { string name; istr >> name; } void makeRecipe(istream &istr, ostream &ostr, list &recipes, Kitchen &kitchen) { string name; istr >> name; }