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

Module specs for an input validation function: isValidInt Return Value: true (if

ID: 641940 • Letter: M

Question

Module specs for an input validation function:

isValidInt

Return Value: true (if inputInt is between min and max, inclusive), false otherwise

Reference parameters: (none)

Receives: inputInt (int), min (int), max (int)

Preconditions: inputInt has been read, min and max have been initialized

Logic: Return true if inputInt is >= min and <= max, false otherwise

Write the function in C++ for the isValidInt function

Then, test the function in a program (you may loop if isValidInt returns false, but at least use an if statement).

Explanation / Answer

#include "ddcpp.h" string UserInput::GetString() { string Input = ""; while (Input == "") { getline (cin, Input);} return Input; } int UserInput::GetInt(int NumberOfChoices) { string Input = ""; int MaxNumber = 0; int IsValidInt = 0; while (IsValidInt == 0){ Input = ""; IsValidInt = 0; MaxNumber = NumberOfChoices; while (Input == "") { getline (cin, Input); } IsValidInt = ValidateInt (Input, MaxNumber); if (IsValidInt == 0) { cout MaxValidNumber) || (InputInt < 0)) { Valid = 0; } if ((InputInt 0)) { Valid = 1; ValidInt = InputInt; } } } else { Valid = 0; } } return Valid; } bool UserInput::ValidateInput(int Input) { int InputInt = Input; int Choice = 0; bool Correct = false; while(Correct == false) { cout
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