Assume the existence of a class RangeException, with a constructor that accepts
ID: 3546618 • Letter: A
Question
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
void verify(int min, int max){
int n;
while(1){
cin >> n;
if(n < min || n > max){
throw RangeException(max, min, n);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.