Question: Question: Array Resizing Ex1. Before calling the function Array = [10,2,3,15,6] Size = 5 After calling the function Array=[2,3,6] size=3 Ex2. Before calling the function
Question: Array Resizing
Ex1.
Before calling the function
Array = [10,2,3,15,6]
Size = 5
After calling the function
Array=[2,3,6]
size=3
Ex2.
Before calling the function
Array = [11,2,3,16,6,17,18]
Size = 7
After calling the function
Array=[11,2,3,16,6,17,18]
size=7
Specification:
- Inputs The function will receive two arguments:
1.the array as reference to a pointer
2.the length as reference to an integer
- Return void
- Function should not return anything
- Function prototype
- void removeDivByFive(/*fill this with pointer reference to the array, int reference to the length */)
Expectations:
- Do not modify the function prototype
- The function should with a new array dynamically and copy the numbers not divisible by 5 from the old array.
- Size of the new array should be exactly the number of elements non-divisible by five.
- There must not be any memory leaks
- Function must use reference to pointer for array and reference to integer for the length
- Code should compile without any errors
arr.cpp
in c++
#include
using namespace std;
void removeDivByFive(/*fill this with pointer reference to the array, int reference to the length */)
{
}
int main(int argc, char* argv[])
{
int size = 5;
int* arr = new int[size];
arr[0] = 10;
arr[1] = 2;
arr[2] = 3;
arr[3] = 15;
arr[4] = 6;
cout<<"before calling the function"< cout<<"size:"< cout<<"arr:"; for(int i=0;i { cout< } cout< removeDivByFive(arr,size); cout<<"after calling the function"< cout<<"size:"< cout<<"arr:"; for(int i=0;i { cout< } cout< }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
