I'm new to c++ and I'm writing an array manipulator program. How would you write a function that removes an element from an array? What parameters would you pass to it? The function cannot have any cout or cin statements, they must be in main instead. How would you call the function? I wrote a function for adding an element to an array, and it looks like this:
int insertValue(int arr[], int value, int pos, int size)
if (size == 10)
cout << "Array full" << endl;
else
{
int i;
for (i = size - 1; i >= pos; --i) {
arr[i + 1] = arr[i];
}
arr[pos] = value;
++size;
}
cout << endl;
return size;
This function works when called. Would removing an element from an array and moving everything to the left follow the same layout? This is what I have so far for that function:
int removeValue(int arr[], int value, int pos, int size)
for (int i = pos; i < size; ++i) {
array[i] = array[i + 1];
}
arr[pos] = value;
return size;
I don't think I have the right idea for this code, which is why I am confused. Can someone explain the idea behind this function and how it would be written correctly?
Thanks for your help!