Objective: To show our understanding of arrays, specifically how to declare, initialize and manipulate the elements of an array. To further our understanding of functions, loops, conditional statements, data types and variables.
Assignment: Write a program that uses an array to store a series of integers. The program should prompt the user to enter elements into the array. After the array has been filled, it should display the initial contents of the array. It should then perform operations to manipulate the elements of the array through specific functions. Note that if the array is modified in any way, the program should re-display the contents of the array.
Procedure:
1. Declare an array of integers of some pre-defined maximum size. You are free to decide the size of the array, but all the elements of the array should be initialized to zero.
2. Implement the following operations on the array through the specified functions:
Postion Value
------- -----
1 10
2 3
3 5
.
.
.
n 7
3. Write the code to control the execution of our program and to test each operation of the array within the body of the main() function.
Note: With the exception of the input() and display() functionis, each of the remaining functions should be independent of all cin and cout statements. In other words, any and all information required by the function should be passed in through parameters. Likewise, information from the function that the caller needs should be returned back either through the return statement or through reference parameters. All information required should be input by the user prior to the function being invoked and all returned information should be output after the function returns control to the caller. In addition, the user should not know anything about the zero based characteristic of arrays. Therefore, if the user needs to specify a location in the array, they should enter from the range 1 to the maximum size of the array and not 0 to max size - 1.
Following is one possible sample run, but feel free to be creative:
Welcome to the world of Arrays!!!!!
Enter element 1: 5
Enter element 2: 7
Enter element 3: 9
Enter element 4: 11
Enter element 5: 5
You have entered:
Postion Value
------- -----
1 5
2 7
3 9
4 11
5 5
The sum of all the numbers entered is: 37
The average of all the numbers entered is: 7.4
The largest number entered is: 11
The smallest number entered is: 5
What number would you like to count? 5
The number 5 appears 2 times.
What number would you like to search for? 5
The number 5 is in position 1.
What element would you like to replace? 5
Enter the new value: 17
The element 5 was replaced 2 times.
Postion Value
------- -----
1 17
2 7
3 9
4 11
5 17
What position would you like to modify? 7
That is an invalid position, please enter a position between 1 and 5: 9
That is an invalid position, please enter a position between 1 and 5: 3
Enter the new value: 13
The contents of your array are now:
Position Value
------- -----
1 17
2 7
3 13
4 11
5 17
What position would you like to clear? Enter the position or -1 to clear entire array: 9
That is an invalid position, please enter a position between 1 and 5, or -1 to clear entire array: -1
The contents of your array are now:
Position Value
------- -----
1 0
2 0
3 0
4 0
5 0