November 25, 2003                                                                                                        Queens College

CS211                                                                                                                                     Instructor: John D. Donath

Test #2

 

Note: This test is open book/open notes.  This means that you can bring in any written or printed reference material for the exam.  However, use of any electronic device during the exam is strictly forbidden.  Communication of any sort with a third party in any manner during the exam will be regarded as cheating.

 

Directions:  Answer all questions by writing the appropriate code, or by sorting the array in the appropriate manner, in the space provided, directly on the test paper.  Only answers written on the test paper will be graded.  If you need extra space, you are allowed to use the back of the exam paper; however, you should make a clear indication on the front so that the graders know to look on the back. 

 

Upon receiving the examination paper and an index card, please write your student ID and test ID on every page of the exam.  Do not write your name on the exam paper.  An Index card will be distributed along with the exam.  Please write your name, testID and studentID on the index card.  These will be collected within the first five minutes of the exam.  You will receive 5% credit for following these directions.

 

Part I (40%)

This question deals with an inheritance hierarchy involving a class called CreditCard (you can call it Credit, for short).  Every credit card has a 16 digit account number, which you should implement as an array of characters (NOT AS AN int).  Credit cards also have a balance, implemented by a float.  For every credit card, you can make a purchase, which adds to your balance, or make a payment, which subtracts from your balance.  There is also a function that is called once a month named finance, which adds a certain percent of your balance to your balance.  This percentage is determined by adding a base (which is set when the credit card is issued) to the prime rate (which it receives as a parameter).  A credit card should also have accessor (get) functions for the account number and balance.

 

There are certain kinds of special Credit Cards that offer rewards for purchases that you make.  For example some of them offer frequent flier miles (1 mile for every dollar of purchase that you make).  Your subclass should keep track of how many miles the user currently has.  The subclass should also have information about how many miles you collected, and a function, redeem, that is called when a user redeems his miles for a plane ticket (it receives the amount redeemed as a parameter).

 

Another kind of special credit card is one that gives 2% of all purchases to a charity.  Whenever a purchase is made, a value shared by all of this type of credit card is updated.  It should also have a function that returns how much was collected for charity by the joint effort of all the users.  (Hint:  Use static variables)

 

A:   Write the .h file of the Superclass (no comments are necessary – 10%)


B:  Write the .h file for the subclass that implements the card with frequent flier miles (10%)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

C:  Write the function purchase, as implemented in the frequent flier miles subclass (10%)


D:  Write a function, not part of any class, which receives a pointer an instance of credit card, an amount, and a percentage, which is the prime rate.  It then applies the amount it receives as a payment to the credit card, and calls the finance function to apply the finance charges.  It returns the amount of finance charges that were debited to the account.  (10%)


Part II (45%):

For this question, you will be asked to write a template class called EvenOdd.  It contains two arrays of any type, one that contains odd numbers, and another that has even numbers.  Both of these arrays are growable to a (theoretically) infinite size. 

The following functions are part of this class:

1.  Insert - Determines which array is the appropriate one to insert into, and then the value is appended to that array.

2.  getElement – Receives two parameters.  The first one is an integer; the second is a Boolean value.  If the Boolean value is true, it returns the values stored at the index given by the first parameter in the first array, if the Boolean value is false, it returns the value stored at the location given by the first parameter in the second array.  If there is no value at the given location it throws an Exception called Index.

3.  == Operator, compares two instances of this class, and returns true if they have the same values in the same order, false if not.

4.  Some other functions may also be necessary.

 

A:  (14%)

Write the .h file for this class:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

B:  Write the insert function defined in the .cpp file of this class.  Note that to receive full credit, you must implement this function recursively. (14%)


C:  Write the = overload for this class (14%)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

D:  What assumptions do your functions make about the nature of the data stored in the class (ie. what operators do they assume are defined) (3%)?

 

 

 

 

 

 

Part III (10%)

A:  Show how the following array will look like after each pass of bubble sort:

20,           10,                 45,                 5,                 6

 

 

 

 

 

 

 

 

B:  How many passes will there be?