Write a function definition for a function named getNeighbors to do the following:  1. Accept an array of integers, the size and an index as input parameters.  2. Return a new dynamic array of size 2 which contains the elements before and after the original index.  3. If the provided index would access an area outside of the array, store 0,0 instead.    Example  1:  Original array is 100 5 25 34 8 with an index 3.  New array would be 25 8.    Example 2:  Original array is 100 5 25 34 8  with an index 0.  New array would be 0 0 since before would be -1 which is an invalid index.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 1TF: Mark the following statements as true or false. A double type is an example of a simple data type....
icon
Related questions
Question

NEED HELP WITH C++...PLEASE PASTE INDENTED CODE 

 

PLEASE USE pointer arithmetic METHOD TO ANSWER

 

Write a function definition for a function named getNeighbors to do the following: 

1. Accept an array of integers, the size and an index as input parameters. 

2. Return a new dynamic array of size 2 which contains the elements before and after the original index. 

3. If the provided index would access an area outside of the array, store 0,0 instead. 

 

Example  1:  Original array is 100 5 25 34 8 with an index 3. 

New array would be 25 8. 

 

Example 2:  Original array is 100 5 25 34 8  with an index 0. 

New array would be 0 0 since before would be -1 which is an invalid index.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning