Skip to the content of the web site.

Project I.2: Interval assignment

In addition to assignment, we will now implement other auto assignment operators:

  • $[a, b] + [c, d] = $[a + c, b + d]$,
  • $[a, b] - [c, d] = $[a - c, b - d]$,
  • $[a, b] * [c, d] = $[\min{ac, ad, bc, bd}, \max{ac, ad, bc, bd}]$,
  • $[a, b] / [c, d] = $[\min{a/c, a/d, b/c, b/d}, \max{a/c, a/d, b/c, b/d}]$ with it being being a domain error if $c \le 0 \le d$,
  • $-[a, b] = [-b, -a]$.

and with scalars:

  • $[a, b] + s = $[a + s, b + s]$,
  • $[a, b] - s = $[a - s, b - s]$,
  • $[a, b] * s = $[\min{as, bs}, \max{as, bs}]$,
  • $[a, b] / s = $[\min{a/s, b/s}, \max{a/s, b/s}]$ with it being being a domain error if $s = 0$,
  • $s / [a, b] = $[\min{s/a, s/b}, \max{s/a, s/b}]$ with it being being a domain error if $a \le 0 \le b$.

This will require you to implement the following member functions:

class Interval {
	public:
		// Other member functions
		Interval  &operator=( Interval const &operand );
		Interval &operator+=( Interval const &operand );
		Interval &operator-=( Interval const &operand );
		Interval &operator*=( Interval const &operand );
		Interval &operator/=( Interval const &operand );

		Interval  &operator=( double s );   // Assigns this to [s, s]
		Interval &operator+=( double s );
		Interval &operator-=( double s );
		Interval &operator*=( double s );
		Interval &operator/=( double s );

		Interval &operator++();
		Interval operator++( int placeholder );
		Interval &operator--();
		Interval operator--( int placeholder );
};

Each of these will be in the form

Interval Interval::operator=( Interval const &operand ) {
	left  = operand.left;
	right = operand.right;

	return *this;
}