Pointers, Dynamic Memory Allocation

In this assignment, you are to implement a program to help a collector of double numbers. He likes doubles and goes on field trips collecting them. However, he does not want to have more than one specimen of the same number in his list. He is somewhat absent minded and occasionally tries to add a number to his list even though he already has it. Your program will help him make sure that he does not have duplicates.

Assignments

  1. Test list. Create a project titled Lab10_Testlist. In the project, you should use the functions prototyped in this header file. You should place the functions you implement in a file named list.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. Number list. Create a project titled Lab10_list. Write a program that allows the user to add a double number to a list or remove a double number from the list. After the operation, the contents of the list should be printed.

    The user 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. The user may request to remove the number that is not in the list, in which case, the program should inform the user and remove nothing.

    Here is an example program dialog:

    enter operation [a/r/q] and number: a 5.0
    your numbers: 5
    enter operation [a/r/q] and number: a 8.0
    your numbers: 5 8
    enter operation [a/r/q] and number: a 8.0
    duplicate!
    your numbers: 5 8
    enter operation [a/r/q] and number: r 8.0
    your numbers: 5
    enter operation [a/r/q] and number: r 10.0
    not present!
    your numbers: 5
    enter operation [a/r/q] and number: a 3.3
    your numbers: 5 3.3
    enter operation [a/r/q] and number: a 12.2
    your numbers: 5 3.3 12.2
    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 check().

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.