162k views
1 vote
Using a pass-by-reference approach, write a function definition that calculates the ideal body weight of an average adult based on the person's height (given in inches) and gender (boolean) using these formulas:

Females: 100 pounds plus 5 pounds for each inch over five feet

Males: 106 pounds plus 6 pounds for each inch over five feet

Here is an example call to the function:

calculateWeight(height, personIsMale, result);

Assume that any numeric data are integers. Do not incorporate any user input or output statements into your answer. Also, do not declare any constants.

When writing the function definition, use a pass-by-reference approach to return the answer by way of the result function parameter.

Remember to only write the function definition for the calculateWeight function. Do not write a complete C++ program.

User Bjarven
by
8.9k points

1 Answer

7 votes

Answer:

void calculate Weight(int height, bool personIsMale, int &result) {

if (personIsMale) {

result = 106 + (height - 60) * 6;

} else {

result = 100 + (height - 60) * 5;

}

}

  • This function definition uses a pass-by-reference approach to calculate the ideal body weight of an average adult based on their height (given in inches) and gender (boolean).
  • It takes three parameters: the height, a boolean representing the person's gender, and a reference variable to store the result.
  • If the person is male, it calculates the ideal weight according to the formula of 106 plus 6 pounds for every inch over five feet.
  • If the person is female, it calculates the ideal weight according to the formula of 100 plus 5 pounds for every inch over five feet.
  • After the calculation, the result is stored in the reference variable.

User Raphael Souza
by
8.9k points

No related questions found