#include <iostream>
using namespace std;
const int CAPACITY=20;
void displayArray(int array[], int numElements);
void fill_array (int array[], int CAPACITY, int &numElements);
int main ()
{
int NumArray[CAPACITY]; int numElements=0;
fill_array(numArray[], numElements);
return 0;
}
void fill_array (int NumArray[], int &numElements)
{
cout << "Enter a list up to 20 integers or -1 to end the list" << endl;
for (numElements=0; numElements<CAPACITY;numElements++)
{
cin >> NumArray[numElements];
}
}
void displayArray(int array[], int numElements)
{
for (int i = 0; i < numElements; i++)
cout << array[i] << " ";
cout << endl;
}
What I have tried:
Example Output:
Enter a list of up to 20 integers or -1 to end the list
3 2 4 8 12 5 6 9 0 11 10 13 -1
3 2 4 8 12 5 6 9 0 11 10 13
Enter a value and a position to insert: 18 5
3 2 4 8 12 18 5 6 9 0 11 10 13
Enter a value to delete from the array: 18
3 2 4 8 12 5 6 9 0 11 10 13
Enter a value to append: 15
3 2 4 8 12 5 6 9 0 11 10 13 15
I have to add all this part in the code:
Start with the simiplest function, e.g., the one to search the content of an array.
The suggested order to write the function is:
Function to search for a value in the array
Function to fill an array with positive integers
Function to delete an element from the array: after deletion, the array should have no holes.
Function to insert an element into the array
Write one function, test it to make sure it really works, and then move on to next function.
Write comments to 1) document your algorithms and design, 2) make your code readable, 3) debug code.