Following completion of this task, students should be able to:
- Write C++ programs using pointer arithmetic and dynamic arrays.
Question 1 (Pointer Arithmetic)
Write a program that performs the following:
Declare and randomly populate an array of integers with 20 positive numbers not greater than 100. The program should determine the median of the array. When a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values. You are required to use a temporary array for the sorting. The original array should not be changed. Display the original array, the sorted array, and the median.
For this task, you are required to use only pointer notation and pointer arithmetic instead of array notation.
Question 2 (Dynamic Arrays)
Write a C++ program that performs the following:
- Request for the number of inputs the user will enter.
- Dynamically create an array of integers using the input required above.
- Let the user enter all the integers in the array (allow duplicates).
- Pass the array to a function that will remove all duplicates form the array. Un-used elements should be removed and the new size should be returned back to main. Use only pointer notation to do this.
- The main() function then display the content of the new array.
Example input/output is shown below:
How many numbers to enter? 7 Enter 7 numbers:
78 45 78 61 45 45 89
Array with no duplicates:
78 45 61 89
Remember to properly de-allocate dynamic memory used in your program.
Reviews
There are no reviews yet.