Question: Write a program in C++ that uses the function locationOfTarget that takes as its arguments: an array of integer values, the size of the

Write a program in C++ that uses the function locationOfTarget " that takes as its arguments: an array of integer values, the size of the array, and an integer "target value".

- The function should return the subscript (position) of the target value.

- If more than one element is equal to the target value, the function should return the largest subscript of the target value.

- If the target value does not occur in the array, the function should return -1.

Thus, for example, if the target value that is passed to the function is 34 and the array that is passed to the function looks like this:

(underscores " _ " are being used for spacing, do not include them)

0 _ _ _ _1 _ _ _ 2 _ _ _ 3 _ _ _ _ 4 _ _ _ 5 _ _ _ 6

58 _ | _ 26 _ | _ 91 _ | _ 34 _ | _ 70 _ | _ 34 _ | _ 88

the target value occurs at 3 and 5, so the function should return the integer value 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!