Question: C++ Write each function as described. Add them to the program below. Add Expected vs. Actual testing for each of these functions, as shown. void

C++

Write each function as described. Add them to the program below.Add Expected vs. Actual testing for each of these functions, as shown.

void findLargestTwo(int x[], int &largest, int &secondLargest) - this function scans the array and returns (via the parameters - the pass by reference largest and secondLargest) the largest and second largest values in the array.

void displayReverse(int x[]) - neatly displays the array values starting at the last value.

bool isAllEven(int x[]) - returns true if all of the values in the array are even numbers, returns false otherwise.

bool inAscendingOrder(int x[]) - returns true if the values in the array are in ascending order.

int countInstances(int [], int target)- returns a count of the instances of target in the values in the array, returning 0 if target is not found in x

To reasonably test the last 3 functions you'll need to declare and initialize some more appropriate arrays. Thus for testing isAllEven you might have:

int x1[ ] = {4, -20, 12, 8, -44);

int x2[ ] = {4, -19, 17, 8, 0};

and then have two expected vs. actual tests - one with a true result, one with a false result.

Here is the program you will start with -

#include using namespace std;

const int MAX = 5;

void displayArray(int[]); int sumArray(int[]); int findMax(int[]);

int main() { int x[MAX] = { 22, -13, 45, 7, 12 }; displayArray(x);

cout cout cout

cout cout cout }

void displayArray(int d[]) { for (int i = 0; i cout } cout }

int sumArray(int d[]) { int sum = 0; for (int i = 0; i sum += d[i]; } return sum; }

int findMax(int d[]) { int maxV = d[0]; for (int i = 1; i if (d[i] > maxV) { maxV = d[i]; } return maxV; }

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 Programming Questions!