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:
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.