Question: Write a full C++ program. New topics that you'll apply in this homework: user input (using cin, getline() and cin.ignore()), arithmetic expressions, constants, math library
Write a full C++ program. New topics that you'll apply in this homework: user input (using cin, getline() and cin.ignore()), arithmetic expressions, constants, math library functions (using pow() ), casting. Remember to have descriptive variable names, a descriptive file name and a descriptive comment about your program. You can have additional comments throughout your code.
A client has approached you about creating a program for health-conscious users. Their suggestion is to include BMI and macronutrients. Macronutrients are carbohydrates, proteins, and fat. Some people are interested in looking at the calories and ratios.
Constants -create the following named constants CAL_PER_GRAM_CARB with a value of 4 CAL_PER_GRAM_PROTEIN with a value of 4 CAL_PER_GRAM_FAT with a value of 9
Variables -Read the sections aboutuser inputandcalculated valuesto decide which variables to declare in your program. You might also decide to create some more constants.
User input.Your program will getuser inputfor the following info:
- first name
- last name
- height in inches Ex: 65 inches. Use a whole number.
- weight in pounds. Use a whole number.
- number of grams of carbohydrates eaten. The grams are whole numbers.
- number of grams of proteins eaten. The grams are whole numbers.
- number of grams of fat eaten. The grams are whole numbers.
- a sentence about their health goals. (suggestion: leave this for last. When you get to it, think about getline() and cin.ignore() )
Arithmetic expressions & math functions:Your program will calculate the following. Decide if you want to create variables for these. Storing some values might be useful, particularly if they will be used again later.
- Calculate the height in feet and inches. Ex 65 inches will be displayed as 5 feet 5 inches (5'5\").
- Calculate the height in meters by taking theheight in inches multiplied by 0.0254Ex: 65 inches is 1.651m.
- Calculate the weight in kg by taking the weight in pounds divided by 2.205. Ex: 184lb is 83.4467kg
- Calculate the body mass index (BMI) by using this formula: Ex: based on the info above, the BMI is 30.6159 Use a math function for calculating BMI and don't forget what to include.
For calculating calories from macronutrients:
- Calculate calories from carbohydrates by taking the \"grams of carbohydrates\" multiplied by the \"calories per gram of carbs\". (Use a constant in this calculation)
- Calculate calories from protein by taking the \"grams ofprotein\"multiplied by the \"calories per gram ofprotein\". (Use a constant in this calculation)
- Calculate calories from fat by taking the \"grams of fat\" multiplied by the \"calories per gram of fat\". (Use a constant in this calculation)
- Calculate total calories by adding: \"calories from carbohydrates\" plus \"calories from protein\" plus \"calories from fat\"
For calculating the percentages.
- Percentage for carbs is \"calories from carbohydrates\" divided by \"total calories\" multiplied by 100.
- Similar calculation for proteins and fats
For the percentages, see if there's an issue withinteger divisionandcastif necessay. Format the output of the percentages to show two digits after the decimal(don't forget what to include). The % sign is part of your string.
Don't do the whole program all at once. It'll be harder for you to identify errors to fix. Write some lines of code and test it out before adding more code. Remember that the program is asequenceof instructions. Order of your statements does matter.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
