Question: c++ Write a short program that prompts the user and reads in integers into an array called Table. When the user enters a negative number,

c++

Write a short program that prompts the user and reads in integers into an array called Table. When the user enters a negative number, the input stops. Keep track of how many numbers were read in (at least 5 and no more than 10; what size should you declare the array to have?)

Then add code to do the following:

1. Print how many numbers were read in, and then print out all the numbers that were stored in the array.

2. Find and print the average. Then find and print how many of the numbers are less than the average calculated above, how many are exactly the same value as the average, and how many were greater than the average. Test and make sure it works.

3. Write a function with the following prototype:

int find (int valueToSearchFor, int intArray[ ], int numberOfValidEnties);

Given an array intTable that has valid values ( how many is given by numberOfVallidEntries), the function searches for valueToSearchFor in the array. If found, the function returns the index number where it was found. If not in the array, the function returns -1.

The function should obey the following restrictions.

a. If valueToSearchFor is found, it should not continue to look at further values in the array.

b. Do not use a break statement.

4. Ask the user for a value and see if it is in the array. If found, the program should print Found at followed by the index where the value was found. Use the find function you wrote. Ask the user whether to repeat and keep repeating if the user wants to. (What kind of a loop statement would be good? The body of the loop would be:

Asking user for a value and reading it in.

Searching for the value in the array and printing either Not found. or Found at index .. Asking user whether to continue and reading in the answer.)

Test using different values. At a minimum, test using the following values:

a. value not in the array.

b. the first value of the array,

c. the last valid value in the array

d. value in the array somewhere between the first and the last valid values.

5. Find and print the smallest value in the array AND the index where it is located. Then write code that will swap the smallest value and the first value in the array.

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!