## CS 1401 Assignment #8

**Date Assigned:** Monday, October 22, or Tuesday,
October 23, 2007.
**Due Date:** Monday, October 29, or Tuesday, October 30, 2007,
before the beginning of your lab section.

**Objective:** The main objective of this assignment is to learn
to design user-defined classes and ADTs.

**Programming assignment:** an interval [a, b] is
characterized by its lower endpoint a and its upper endpoint b. A
midpoint of the interval is defined as (a + b)/2, and its width is
defined as b - a.

Arithmetic operations on the intervals are defined based on the
following logic. For example, for addition, if I have between 5 and 8
dollars with me, and my friend has between 10 and 30, then the smallest
amount we have together is 5 + 10 = 15, and the largest is 8 + 30 = 38.

For subtraction, if I have between 10 and 30 dollars, and I spend between
5 and 8 for lunch, then the smallest amount that will remain is
when I had the smallest amount and spend the largest amount, i.e.,
10 - 8 = 2. The largest remaining amount is when I had most money and
spent the least amount of money, i.e., 30 - 5 = 25.

As a result, the arithmetic operations with intervals are defined as
follows:

[a, b] + [c, d] = [a + c, b + d]
[a, b] - [c, d] = [a - d, b - c]
[a, b] * [c, d] = [min(a*c, a*d, b*c, b*d), max(a*c, a*d, b*c, b*d)]
1/[a, b] = [1/b, 1/a] if 0 is not in the interval [a, b]
(and undefined otherwise)
[a, b]/[c, d] = [a, b] * (1/[c, d])

Describe a class whose elements are intervals, and methods
include:

- a constructor method,
- methods to return (accessor) and
to change (mutator) the values of the parameters,
- methods for computing the midpoint and the width of an interval,
and
- method for the
arithmetic operations.

Use your class in
the main program to create the intervals [5, 8] and [10, 30] and to
check that [5, 8] + [10, 30] = [15, 38] and [10, 30] - [5, 8] = [2, 25].
**Homework assignment:** on a separate sheet of paper, solve Ex.
6 from p. 520 and Ex. 16 from p. 522.

**Deliverables:** as instructed by your TA.