Question
The Research: Among some useful sources of nutritional information is http://nutritiondata.self.com. Enter a food name (like garbanzo beans) and find the closest match from the
The Research: Among some useful sources of nutritional information is http://nutritiondata.self.com. Enter a food name (like "garbanzo beans") and find the closest match from the list you get (say "Chickpeas, boiled without salt"). Use the pull-down to get "Serving Size = 100 gm". Then scroll down to find the nutrients you are interested in. In some cases, you may have to refer to an additional page, say, if the nutrient happens to be too detailed for that site. For example, in my program, I selected "soluble fiber" as one of the nutrients, but nutritiondata.self.com only gives total fiber, so I had to look elsewhere (e.g., (http://huhs.harvard.edu/assets/File/OurServices/Service_Nutrition_Fiber.pdf or a similar fiber-specific reference) and do some conversions to find out how much soluble fiber was in 100g of my ingredient
. A Simple Framework to Start
#include
#include
#include
#include using namespace std;
// main client --------------------------------------------------------
int main()
{
// food #1constants
const string FOOD_1_NAME = "avocado";
const int FOOD_1_CALORIES_P100G = 160;// in calories
const double FOOD_1_SOL_FIBER_P100G = 1.75; // in grams
// food #2 constants
const string FOOD_2_NAME = "tomato";
const int FOOD_2_CALORIES_P100G = 18; // in calories
const double FOOD_2_SOL_FIBER_P100G = .12; // in grams
// food #3 constants
const string FOOD_3_NAME = "buffalo mozzarella";
const int FOOD_3_CALORIES_P100G = 282; // in calories
const double FOOD_3_SOL_FIBER_P100G = 0.; // in grams
string recipeName, userInputStr;
int userInputInt;
double totalSolFiber, totalCals;
// initialize accumulator variables
totalSolFiber = 0.;
totalCals = 0;
// print menu
cout << "---------- List of Possible Ingredients ---------" << endl;
cout << " Food #1: " << FOOD_1_NAME << endl;
cout << " Food #2: " << FOOD_2_NAME << endl;
cout << " Food #3: " << FOOD_3_NAME << endl << endl;
// name of recipe
cout << "What are you calling this recipe? ";
getline(cin, recipeName);
// food #1 ---------------------------------------------------------
cout << "How many grams of " << FOOD_1_NAME << "? ";
getline(cin, userInputStr); istringstream(userInputStr) >> userInputInt;
// update accumulators
totalCals += userInputInt * (FOOD_1_CALORIES_P100G/100.);
totalSolFiber += userInputInt * (FOOD_1_SOL_FIBER_P100G/100.);
// food #2 ---------------------------------------------------------
cout << "How many grams of " << FOOD_2_NAME << "? "; getline(cin, userInputStr);
istringstream(userInputStr) >> userInputInt;
// update accumulators
totalCals += userInputInt * (FOOD_2_CALORIES_P100G/100.);
totalSolFiber += userInputInt * (FOOD_2_SOL_FIBER_P100G/100.);
// food #3 ---------------------------------------------------------
cout << "How many grams of " << FOOD_3_NAME << "? ";
getline(cin, userInputStr); istringstream(userInputStr) >> userInputInt;
// update accumulators
totalCals += userInputInt * (FOOD_3_CALORIES_P100G/100.);
totalSolFiber += userInputInt * (FOOD_3_SOL_FIBER_P100G/100.);
// report results --------------------------------------------------
cout << " Nutrition for " << recipeName << "------------" << endl;
cout << " Calories: " << totalCals << endl;
cout << " Soluble Fiber: " << totalSolFiber << endl;
return 0;
}
Notice that the user gets a list of three ingredients and selects quantities of each for his/her recipe.
English Language Hint: An ingredient is something you would buy and use in the recipe. It could be a vegetable or a brand name of some pre-cooked mixture. Examples of ingredients are tomatoes, avocado, olive oil,Campbell's beef broth, sugar, garlic, split peas, soy beans, tofu, pasta, etc.
The program asks for every one of the ingredients for your recipe, so if one is not included in the recipe, the user has to answer "0" when prompted for the # of grams.You can see how I provided ingredients that can make two very different dishes, depending on which ones the user chooses.
Your Assignment: You will have some fun embellishing the above program as follows:
1. Display a list of between four and six ingredients to the console (instead of my three).
2. Define between four and six nutrient constants (instead of my two). I defined and computed calories and soluble fiber, but you will define and compute four, which may include those two, or be four entirely different nutrients. English Language Hint: A nutrient is something like calories, protein, fat, vitamin C, fiber. These are compounds that are found in foods.
3. Prompt for, and receive, the number of servings, e.g., two (2) or nine (9), and instead of giving the nutritional breakdown of the entire recipe, only state the nutritional value in a single serving. English Language Hint: A serving is how much you serve to one person. If the recipe says it "serves seven" that means that you follow the directions and amounts exactly, but when you are done, you divide the food you made into seven equal portions. Each portion is one serving.
4. Add error testing. If the user enters an amount (grams) either < 0 or > 1000, end the program, instantly, with an error message. If the user enters a number of servings < 1 or > 10, end the program, instantly, with an error message.
You don't have to use my ingredients or nutrients, but you may. Run the program at least five times entering different recipes, and making an input error in one of those five runs, exercising your error testing. Submit all five runs with your source.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started