Public feed
#726269
#include <string>
#include <list>
#include <fstream>
#include <algorithm>
#include "ingredient.h"
class Recipe
{
public:
Recipe(std::string tname);
//accessors
std::string getName() const;
std::list<Ingredient> getIngredients() const;
//Member functions
void addIngredient(std::string name, int unit);
void printRecipe(std::istream &istr, std::ostream &ostr);
std::list<Ingredient> ingredients;
private:
//Member variables
std::string name;
};
Recipe::Recipe(std::string tname)
{
name=tname;
}
void Recipe::addIngredient(std::string name, int units)
{
Ingredient ing(name,units);
ingredients.push_back(ing);
}
std::string Recipe::getName() const
{
return name;
}
std::list<Ingredient> Recipe::getIngredients() const
{
return ingredients;
}
void Recipe::printRecipe(std::istream &istr, std::ostream &ostr)
{
ostr << "To make " << name << ", mix together:" << std::endl;
ingredients.sort(sortabc);
std::list<Ingredient>::iterator l_itr=ingredients.begin();
for(l_itr;l_itr!=ingredients.end();l_itr++)
{
if((*l_itr).getUnits()==1)
ostr << " " << (*l_itr).getUnits() << " unit of " << (*l_itr).getName() << std::endl;
if((*l_itr).getUnits()>1)
ostr << " " << (*l_itr).getUnits() << " units of " << (*l_itr).getName() << std::endl;
}
}