Question: /* It works with a struct type called height. It allows the user to enter heights, have heights grow and print heights. */ #include #include

/*

It works with a struct type called height. It allows the user

to enter heights, have heights grow and print heights.

*/

#include

#include

using namespace std;

int main()

{

int inches,// number of inches to grow, user entered

inch; // counter for inches grown so far

cout << "Enter the first person's height";

input_height (p1);

cout << " Enter the second person's height";

input_height (p2);

cout << " Person 1";

print_height (p1);

cout << " Person 2";

print_height (p2);

cout << " Enter a number of inches for Person 1 to grow: ";

cin >> inches;

for (inch = 0; inch < inches; inch++)

grow (p1);

cout << " Person 1 after growing " << inches << " inches";

print_height (p1);

cout << " ";

return 0;

}

  • Declare a struct called height before main. height has two int fields called feet and inches.

  • Declare two variables of type height in main called p1 and p2.

Write a prototype and function definition for a function called input_height. It takes one call by reference parameter of type height. It does not return a value. It prompts the user for a number of feet and inches for a person and sets these fields for the given parameter.

Write a prototype and function definition for a function called grow. It takes one call by reference parameter of type height. It does not return a value. It increases the height of its parameter by 1 inch. The function should change feet when appropriate.

Write a prototype and function definition for a function called print_height. It takes one call by value parameter of type height. It does not return a value. It prints the number of feet and inches in its parameter in a nicely labeled fashion. For example:

feet: 6 inches: 3

The program should now run: prompts the user for 2 heights, prints the heights entered, prompts the user for an amount to grow and prints the height after growing.

1. Remove the semicolon from the end of the struct declaration. Compile your program. What happens ?

Change your program back.

2. Comment out the prompt and call to input_height for p2. What values are printed for p2 and why?

Change your program back.

3. Change the parameter in grow, prototype and definition, to call by value. Run your program (it should run!). How does this change the output and why?

Change your program back.

4. Show a statement that the programmer can place in main that will assign the number of inches of the height variable p2 equal to 345.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!