Write the implementation for the class declaration below. class Range { friend o
ID: 3654439 • Letter: W
Question
Write the implementation for the class declaration below.
class Range {
friend ostream & operator<<(ostream &, const Range & r); // e.g. [3,5]
public:
// initialize minimum to the smaller of mini,maxi and maximim to the bigger
Range(int mini, int maxi);
const int minimum, maximum;
bool isIn(int val) const; // return true if val in the interval [minimum, maximum]
};
Driver code is below.
int main() {
int mn, mx;
cin >> mn >> mx;
Range r(mn,mx);
cout << "The range is " << r.minimum << " to " << r.maximum << " inclusive." << endl;
for (int i = r.minimum-3; i <= r.maximum+3; i++)
cout << left << setw(4) << i
<< (r.isIn(i) ? " is " : " isn't")
<< " in " << r << endl;
return 0;
}
A sample run:
3 1
The range is 1 to 3 inclusive.
-2 isn't in [1,3]
-1 isn't in [1,3]
0 isn't in [1,3]
1 is in [1,3]
2 is in [1,3]
3 is in [1,3]
4 isn't in [1,3]
5 isn't in [1,3]
6 isn't in [1,3]
Press any key to continue . . .
Explanation / Answer
class Range { friend ostream & operator mn >> mx; Range r(mn,mx); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.