522 Chapter 11 Abstract Data Types and Encapsulation Constructs
the parts of a complex number, and construction of a complex number
from two floating-point constants, variables, or expressions. Use Ada,
C++, Java, C#, or Ruby.
- Write an abstract data type for queues whose elements store 10-character
names. The queue elements must be dynamically allocated from the
heap. Queue operations are enqueue, dequeue, and empty. Use either
Ada, C++, Java, C#, or Ruby. - Write an abstract data type for a queue whose elements can be any prim-
itive type. Use Java 5.0, C# 2005, C++, or Ada. - Write an abstract data type for a queue whose elements include both a
20-character string and an integer priority. This queue must have the
following methods: enqueue, which takes a string and an integer as
parameters; dequeue, which returns the string from the queue that has
the highest priority; and empty. The queue is not to be maintained in
priority order of its elements, so the dequeue operation must always
search the whole queue. - A deque is a double-ended queue, with operations adding and removing
elements from either end. Modify the solution to Programming Exercise
7 to implement a deque. - Write an abstract data type for rational numbers (a numerator and a
denominator). Include a constructor and methods for getting the numer-
ator, getting the denominator, addition, subtraction, multiplication, divi-
sion, equality testing, and display. Use Java, C#, C++, Ada, or Ruby.