We will now want to perform arithmetic operations on intervals and scalars:
This will require you to implement four member functions using operator overloading and four friend functions:
class Interval {
public:
// Other member functions
Interval operator+( double s ) const;
Interval operator-( double s ) const;
Interval operator*( double s ) const;
Interval operator/( double s ) const;
friend Interval operator+( double s, Interval const &operand );
friend Interval operator-( double s, Interval const &operand );
friend Interval operator*( double s, Interval const &operand );
friend Interval operator/( double s, Interval const &operand );
};
Where possible, many of these functions should be written in the form
Interval Interval::operator+( double s ) const {
Interval result{*this};
result += s;
return result;
};