Implement a range function for a dynamic array which returns a new dynamic array that is a subset of the original. input parameters: array - (the array and any related parameters) start - index of the first element end - index of the last element Interval - An integer number specifying the incrementation of index This function returns a new dynamic array containing the elements from the start thru the end indices of the original array. All array indexing must be done using pointer arithmetic. For example, given the array: 49 96 99 47 76 29 22 16 30 22 If the start and end positions were 5 and 9 with step 2, return a new dynamic array: 29 16 22 Please use following main to test your function. int main(){ int *p = new int[10]{49,96,99,47,76,29,22,16,30,22}; int *q = range(p,10,5,9,2); for(int i=0;i<3;i++) cout<
Implement a range function for a dynamic array which returns a new dynamic array that is a subset of the original.
input parameters: array - (the array and any related parameters) start - index of the first element
end - index of the last element
Interval - An integer number specifying the incrementation of index
This function returns a new dynamic array containing the elements from the start thru the end indices of the original array.
All array indexing must be done using pointer arithmetic.
For example, given the array: 49 96 99 47 76 29 22 16 30 22
If the start and end positions were 5 and 9 with step 2, return a new dynamic array: 29 16 22
Please use following main to test your function.
int main(){
int *p = new int[10]{49,96,99,47,76,29,22,16,30,22}; int *q = range(p,10,5,9,2);
for(int i=0;i<3;i++)
cout<<q[i]<<" "; // print 29 16 22 cout<<endl;
delete [] q;
q = range(p,10,1,8,3);
for(int i=0;i<3;i++)
cout<<q[i]<<" "; // print 96 76 16
cout<<endl;
delete [] q; }
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images