Charlie's Collection

Pointers, Dynamic Memory Allocation

Study Observing Variables feature of MSVS described here. As you work on the below project, demonstrate to the instructor displaying local variable values with "Autos" and "Locals" tab.

Charlie is an avid collector of double numbers. He likes numbers and goes on field trips collecting them. However, Charlie does not want to have more than one specimen of the same number in his collection. Yet, he is somewhat absent minded and occasionally tries to add a number to his collection even though he already has it. Your program should keep track of Charlie's collection and make sure there are no duplicates.

Assignments

  1. Test Collection. Create a project titled Lab10_TestCollection. In the project, you should use the functions prototyped in this header file. You should place the functions you implement in a file named collection.cpp. Your code should work with this test file The functions to be implemented are as follows:

    Hint: double *p=new double[0]; works correctly: returns a pointer to zero-size array (array with no elements). This allows to avoid treating the array of size zero in the above functions as a special case.

  2. Charlie's Collection. Create a project titled Lab10_CharliesCollection. Write a program that allows Charlie the user to add a double number to a collection or remove a double number from the collection. After the operation, the contents of the collection are printed.

    Charlie may enter the number twice, in which case, the program should inform that it is a duplicate and the duplicate number should not be entered. Charlie may request to remove the number that is not in the collection, in which case, the program should inform the user and remove nothing.

    Here is an example program dialog (Charlie's input is in bold):

    Charlie, enter operation [a/r/q] and number: a 5.0
    your numbers: 5, sum: 5
    Charlie, enter operation [a/r/q] and number: a 8.0
    your numbers: 5 8, sum: 13
    Charlie, enter operation [a/r/q] and number: a 8.0
    duplicate!
    your numbers: 5 8, sum: 13
    Charlie, enter operation [a/r/q] and number: r 8.0
    your numbers: 5, sum: 5
    Charlie, enter operation [a/r/q] and number: r 10.0
    not present!
    your numbers: 5, sum: 5
    Charlie, enter operation [a/r/q] and number: a 3.3
    your numbers: 5 3.3, sum: 8.3
    Charlie, enter operation [a/r/q] and number: a 12.2
    your numbers: 5 3.3 12.2, sum: 20.5
    Charlie, enter operation [a/r/q] and number: q
    

    The size of the user input can be arbitrarily large. For this program, to accommodate user input, you need to implement an array of doubles whose size varies as necessary. The numbers in the array should not be sorted.

Milestone: implement functions output() and value().

Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository. Do not forget to verify your submission on the web.