October 21, 2003                                                                                                   Queens College

CS211                                                                                                                     Instructor: John D. Donath

Test #1

 

Note:  This test is open book/open notes.  This means that you are allowed to use references from textbooks, notes or other sources.  You are not allowed to refer to any electronic sources, or operate any electronic devices during the exam.  Any form of communication during the examination will be considered cheating.  You may use any paper that you like for scrap; however, only answers written on the examination paper will be graded.  Please do not staple or hand in additional sheets of paper.

 

Directions:  Please write the test ID and your student ID on every page of the test.  At the end of the test, you must hand in all the papers that you received.  Also, please write your name, testID and studentID on the index card that you received along with the test.  The index cards will be collected within the first 5 minutes of the examination.  Please do not write your name on the test paper.  You will receive 5 points for following these and all other directions.

Answer all the questions directly on the test paper, on the space provided.

 

You may use the following class on the exam.  You need not provide its implementation.  You may also use any library classes that you wish, so long as the appropriate library paths are included in your code:

 

/**

 * Keeps track of data about a stamp.  Data we wish to store include the year it was made, monetary value

 * and a brief description of the stamp.

 *

 * @author:  John D. Donath

 */

class Stamp {

                public:

                                Stamp(); // Creates an instance of this stamp with default values

                                                // (made in 2003 and worth $1, no description)

                                Stamp(int y, float v); // Sets the values stored in the class to those passed by the

                                                                // parameters.  Description becomes the empty string

                                Stamp(int y, float v, string d);  // Sets the values stored in the class to those passed

                                                                // by the parameters.

                                int getYear() const {return yearMade;}

                                float getValue() const {return value;}

                                string getDescription() const {return description;}

                                void setDescription(const string& str) { description = str; }

                private:

                                int yearMade;

                                float value;

                                string description;

};

 

For this exam, you will be working with the class StampCollection that implements a collection of stamps.  Different parts of the exam will involve different phases in the lifetime of StampCollection.  StampCollection should store a growable list of stamps, given by the class above.  StampCollection should have the following capabilities:

                1.  Add a stamp to the collection

                2.  Retrieve a stamp from the collection using an index, [].  Note that the user should not be able to use the [] to modify stamps in the collection.

                3.  Ability to merge two StampCollection classes by using the + operator.  Note that the merged class should contain all the stamps in both of the classes.

                4.  Remove a stamp from the collection

                5. Return all the stamps in the collection that were printed in a given year (specified by a parameter).

                6.  Return all the stamps that have a certain value or more.

                7.  Compare two collections using the == operator. *

                8.  Compare two collections using the != operator.  *

*Note:  Two StampCollection classes are considered equal if they have the same stamps in the same order.


Part I:

1.  Write the complete .h file for the class StampCollection.  Please provide the complete file including all necessary includes, macro definitions and function declarations.  You need not comment your code (30%).


Part II:

Implement the following functions that are in the .cpp file for the StampCollection class.  You need not implement the complete .cpp file.  You should implement only the functions that are listed. Write all your code on this page and the next page.

 

1.  The function that adds a stamp to the collection (10%).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.  The overload of the + operator (10%)


3.  The function that returns all the stamps in the collection that were printed in a given year (10%)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4.  The overload of the = operator (10%)


Part III:

Implement the following function in the file that contains the main program (25%):

 

Write a function that receives as a parameter an instance of the class StampCollection, a string, and an integer.  It will append the string it received to the description of all the stamps in the stamp collection that were dated before the integer that was passed to it.

 

For example, if I called this function in the following way:

StampCollection, sc;

// Some more code here

modify(sc, “old”, 1903);

 

It will append the word old to the description of every instance of stamp in the collection sc that was printed before 1903.

(Note that the string class has a constructor that takes in a c-string as a parameter.)