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.
make sure only odd values are added. Even values should be ignored
Use check() to check if the number is already present in the array.
A binary seach should be done to check the list. Use any stl functions you deem helpful
If yes, no further actions are required. If the number is not present, it needs to be added. The array cannot be enlarged to accommodate the number. Instead, this function needs to allocate a new array whose size is one more than the size of the old array, copy the contents of the old array to the new one, include the new number, deallocate the old array and then assign the address of the new array back to the original pointer.Note that since the pointer is passed by reference, the call to this function results in effectively "enlarging" the array pointed to by the pointer.
remember it is of the upmost importance that evan number never be allowed in the array. Only odd values. It is also important that the check function uses binary seach as anything else will take too long
Again, use check() to check if the number is present in the array. If the number is not present, no further actions are required. If the number is present, then the function should allocate a new array of smaller size and then copy all the numbers to it, except the one that needs to be erased. After copying is done, deallocate the old array and update the array pointer to point to the new array.
Copying and removing one element may be done in a single for-loop. Here is a pseudocode for the solution:
create a boolean variable "found", set it to false
iterate over elements in the old array,
if old array element equals to the number to be removed then
set found to true
else
if not found then
copy old array element to the new array element
else // found
copy old array element to the new array
element with index one less than old array's
(move them to the left)
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.
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.