Question: Use a text editor (e.g., the Code::Blocks editor, NotePad, or vi) to make your first pseudocode statement of the problem. Each time you refine a
Use a text editor (e.g., the Code::Blocks editor, NotePad, or vi) to make your first pseudocode statement of the problem.
Each time you refine a step, copy and paste your current version of the function design to the end of your text file, then make your change. Try to follow the instructors convention of using different number of ** to indicate the level of expansion responsible for each statement. When you are done with the design, you should have a complete record of the design process you followed to reach your final design.
Problem Description: Calorie Counter
The USDA maintains a Nutrient Database on a wide variety of food stuffs. A typical entry in that database might indicate how many calories are in a 1/4 cup of flour or a tablespoon of butter.
A recipe will contain a list of ingredients with the appropriate amount of each ingredient required. To simplify this program, we will assume that the same units of measurement are used in the recipe as in the nutrient database, though the amounts may differ. The recipe is likely to make multiple servings of the final food item.
Design a program to read a set of entries from the Nutrient Database and a recipe, and to print the number of calories in a single serving of a food prepared from that recipe.
Input
The program should accept two file names as command parameters. The first name is the name of the nutrients file. The second will be the name of the recipe file.
Each line in the nutrient file will contain information on one ingredient. This information will consist of the following fields:
name amount units calories
with one or more blanks between each field, where
name is the name of the ingredient, a string. The name will be left-justified (i.e., no blanks at the start of the line) and the end of the name will be indicated by a semi-colon (;). Names may contain blanks.
amount is a floating point number indicating how much of the ingredient the USDA used when measuring the calories,
units is the name of the units of measurement in which amount was measured. This will be a string with no internal blanks.
calories is a floating point number indicating how many calories were found in the indicated amount of that food item.
The recipe file will begin with one line containing the title of the recipe. The next line will contain a single floating point number indicating how many servings are prepared by the recipe. Each subsequent line will describe a single ingredient via the fields
amount units name
with one or more blank spaces between each field. The meanings of these fields correspond to the meanings in the nutrient file, except that here the amount reflects the amount actually used in the recipe.
Not every ingredient listed in the nutrient file need be used in the recipe. It is also possible that a recipe will call for an ingredient not listed in the nutrient file or may use units of measurement different from those in the nutrient file.
Output
The program should produce as output a line reading:
One serving of AAA contains BBB calories.
where AAA is the title of the recipe and BBB is either
the total number of calories in one serving, rounded to the nearest integer, if every ingredient in the recipe matched an entry of the nutrient file in both name and units.
the phrase at least NNN, if not every recipe ingredient could be matched, where NNN is the total number of calories in one serving, rounded to the nearest integer, of those ingredients in the recipe that did match an entry of the nutrient file in both name and units.
Example
If the program were invoked like this:
./calories nutrients0.dat recipe0.dat
where the file nutrients0.dat contained
graham crackers; 2 squares 59 milk chocolate; 1 bar 235 cheese, swiss; 1 oz 108 marshmallows; 1 cup 159
and recipe0.dat contained
S'mores 2 4 squares graham crackers 1 bar milk chocolate 2 large marshmallows
the output should be
One serving of S'mores contains at least 177 calories.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
