C++ Assume the existence of a class RangeException, with a constructor that acce
ID: 3713098 • Letter: C
Question
C++ Assume the existence of a class RangeException, with a constructor that accepts minimum, maximum and violating integer values (in that order). Write a function, void verify(int min, int max) that reads in integers from the standard input and compares them against its two parameters. As long as the numbers are between min and max (inclusively), the function continues to read in values. If an input value is encountered that is less than min or greater than max, the function throws a RangeException with the min and max values, and the violating (i.e. out of range) input.
Explanation / Answer
#include <iostream>
using namespace std;
void verify (int min, int max)
{
int input;
cin >> input;
while (input <max && input >min)
{
cin >> input;
if(input > max || input < min)
{
throw RangeException (min, max, input);
}
}
}
==========================================================================
Thanks, let me know if there is any concern.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.