CIS 330 Home Page Last updated 2008/02/27 11:33:57

CIS 330 Extra Credit Problems


Use the web service e-turnin to submit your work electronically. You may turn in revisions of your homework up to the time it is due.

The problems in this assignment are optional. You can do any or all of the problems for extra credit toward your assignment score total. Each problem is worth 40 points.


  1. Write a C++ class named Complex that behaves like a complex number. A complex number consists of two parts, the real part and the imaginary part, and is represented as a + bi where a and b are real numbers and i is the square root of -1. Your class should define appropriate constructors, arithmetic operators, comparison operators, and an output operator.

    Use the driver code complexTest.c to test your implementation and determine the behavior you must implement. Note that this driver does various tests of operations, but your solution should have complete sets of operators. That is, the driver may only use ==, but you should define both == and !=. Likewise, the driver may only use a few arithmetic operators, but you should define addition, subtraction, multiplication, and division, and the compound assignment forms of these as well. Define the interface to your class in a file named Complex.h and the implementation in a file named Complex.c.

    Running this program should produce the following:

    b is 1.2 + 2.35i
    c is 2.3 + 5.45i
    e is 2.3 + 5.45i
    d is -8.4 + 6.82i
    f is -8.4 + 6.82i
    Now d is 1.23591 + 0.163016i
    Now f is -1.23591 + -0.163016i
    a is 2.3 + 5.45i
    c is 3.3 + 5.45i
    a and c are different
    b is 5 + 0i
    5 and b are the same
    


  2. Write a class Queue that implements a simple queue. The objects enqueued should be QueueNode objects, and the idea here is to implement QueueNode as an abstract base class from which you can inherit. The QueueNode objects only have to supply a method for printing to an output stream.

    The driver code queueTest.c defines a Customer object that derives from QueueNode and simulates a set of checkout lanes with customers randomly assigned to a lane and checked out. The amount of time taken by a customer is effectively random, but each queue maintains the order of the customers on a first in, first out basis.

    Use the driver code to test your implementation of Queue and QueueNode. Define the interface to both your classes in a single file named Queue.h and the implementation in a file named Queue.c.

    Running this program with values 3 and 10 could produce the following:

    Customer1 (entered at 2) checked out at 6
    Customer5 (entered at 9) checked out at 10
    Customer2 (entered at 4) checked out at 12
    Customer4 (entered at 8) checked out at 17
    Customer3 (entered at 5) checked out at 25
    Customer7 (entered at 13) checked out at 28
    Customer8 (entered at 14) checked out at 31
    Customer9 (entered at 15) checked out at 38
    Customer6 (entered at 11) checked out at 42
    Customer10 (entered at 16) checked out at 43
    


  3. Write a class Stack that implements a generic stack data structure. This should be a template version of a stack that can be used with any data type that has an output operator and can be assigned. Your implementation must provide push and pop methods as well as an empty predicate. Your class must also contain a dump method for debugging and should also support copying of stacks.

    The driver code stackTest.c shows how your Stack class must work. Put your code all in a single header file Stack.h.

    This driver produces the following results:

    Stack contains: [21 19 17 15 13 11 9 7 5 3]
    21 19 17 15 13 11 9 7 5 3 
    Stack contains: []
    Stack contains: [14 13 12 11 10 9 8 7 6 5 4 3 2 1 0]
    Stack contains: [7 6 5 4 3 2 1 0]
    Curly Moe Harry Dick Tom