Question: in C++ please Question 1: [20 points) Write and test the function bool replace (int *ptr, int from, int to); that changes all the occurrences
Question 1: [20 points) Write and test the function bool replace (int *ptr, int from, int to); that changes all the occurrences of from in the integer array pointed at by ptr to to. For example, if ptr is pointed at the integer array is 1, 2,2,3,5, -1", and from is 2 and to is 6, ptr would become 1, 6, 6, 3, 5, -1". If at least one element of the array pointed at by ptr is replaced, then the function returns True, False otherwise. Use ptr as a traveling pointer which stops when encounter the sentinel value - 1. Write a suitable main () program to test replace(). Sample Input: Array Elements: 1 2 2 3 5-1 from: 2 to: 6 Output: 1 6635
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
