Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The GetInt(string) function of Exercise 4.4 is designed to be generic function w

ID: 3652658 • Letter: T

Question

The GetInt(string) function of Exercise 4.4 is designed to be generic
function which can be used anytime we need to display a prompt and read an integer from the keyboard. For example,
suppose we also wish to read a person's height in addition to reading their age. We could write the code two ways: (1) write
two functions, GetAge() and GetHeight(), which essentially do the same thing; and then call GetAge() and GetHeight() from
main(); or (2) write one function, GetInt(string) as described above; and then call GetInt(string) twice from main()

Explanation / Answer

#include #include using namespace std; int GetInt(string prompt) { int n; coutn; return n; } int main() { string prompth("Enter your Height: "); string prompta("Enter your Age: "); int height = GetInt(prompth); int age = GetInt(prompta); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote