ITI 1121 Midterm: ITI 1121 University of Ottawa 2007 Midterm-en

26 views18 pages

Document Summary

A tuple holds two natural numbers (objects of the class natural). All the tuples have a method getfirst, as well as a method getsecond, returning a reference to the rst, and second, number of the tuple, respectively. A tuple has a method divides that returns true if the rst element is a factor of the second element, and false otherwise. For this question there is an interface named tuple, an abstract class named abstracttuple, and two concrete implementations, called pair and arraypair. Their complete description can be found on the next pages. The implementation of the class natural is given on page 18. The execution of the statements below produces the following output: 7 is a factor of 42. Natural n1, n2, n3; n1 = new natural( 7 ); n2 = new natural( 17 ); n3 = new natural( 42 );