Public feed #725876

Ingredient class

public text v1 · immutable
Raw Edit
·published 2007-10-04 19:14 UTC
rendered paste body
#include <string>

class Ingredient
{
   public:
          
   Ingredient(std::string tname,int tunits);
   
   int getUnits() const;
   std::string getName() const;
      
   private:
   int units;
   std::string name;   
};

Ingredient::Ingredient(std::string tname,int tunits)
{
 units=tunits;
 name=tname;                                  
}

int Ingredient::getUnits() const
{
    return units;
}

std::string Ingredient::getName() const
{
    return name;
}

//Sort helper function
bool sort123(Ingredient ing1,Ingredient ing2) 
{
   if(ing1.getUnits() > ing2.getUnits())
      return false;
   if(ing1.getUnits() == ing2.getUnits() && ing1.getName() > ing2.getName())
      return false;
   return true;
}