
Write a void function that prints the list of nonnegative integers in reverse.
Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the number of such numbers found.
Write a function that determines the largest value stored in the array and returns that value to the calling function main.
Write a function that determines the number of even integers stored in the array and returns that value to the calling function main.
Write a function that calculates the average of the values stored in the array and returns that value. to the calling function main.
Write the function calls with the appropriate arguments in the function main. Any values returned will be output.
Write appropriate block comments for each function header similar to the ones provided. Show your understanding of the program and thus provide useful information to the reader.
Test all the functions using appropriate test data.
Use the following code and edit it where needed.
#include <iostream> //for cin, cout
using namespace std;
const int MAX_SIZE = 20; // maximum size of array
//function prototypes
void ReadList(int[], int&);
void PrintList(const int[], int);
int main()
{
int list[MAX_SIZE]; // array of nonnegative integers
int numberOfIntegers = 0; // number of nonnegative integers in array
ReadList(list, numberOfIntegers);
PrintList(list, numberOfIntegers);
//output your name etc.
cout << "123\n\n";
system("pause");
return 0;
}
//***************************************************************************
// Definition of function ReadList.
// This function reads nonnegative integers from the keyboard into an array.
// The parameter list is an array to hold nonnegative integers read.
//The parameter length is a reference parameter to an int. It holds the
// number of nonnegative integers read.
//***************************************************************************
void ReadList(int list[], int& length)
{
int number;
int index = 0;
cout << "\n\nEnter nonnegative integers each separated by a blank space,\n"
<< " and mark the end of the list with a negative number: ";
cin >> number; //read the first integer entered
//check that the number is nonnegative and
// the size of the array is not exceeded
while (number >= 0 && index < MAX_SIZE)
{
list[index] = number; //store the integer in the array
index++; // increment the index
cin >> number; // read the next integer
}
length = index; // length is the number of nonnegative integers
// in the list
}
//***************************************************************************
// Definition of function PrintList.
// The function prints the nonnegative integers in the array list and the
// number of integers in the array.
// The parameter list holds the nonnegative integers
// The parameter length holds thenumber of nonnegative integers.
//***************************************************************************
void PrintList(const int list[], int length)
{
int index;
cout << "\nThe list contains " << length
<< " nonnegative integer(s) as follows: \n";
for (index = 0; index < length; index++)
cout << list[index] << " ";
cout << endl;
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

- Complete the code.arrow_forwardWhen calling a function, what exactly does it imply to say that you need the "base address of an array"?arrow_forwardWrite the main program to create an array of size 10. Create two integer variables called max and min. Write a function to accept this array and its size. This function must populate the array with random numbers in the range -400 to 300. Write a different function to accept this array, its size and the address of the two variables max and min. The function must find the max and min of this array and write it to the min and max using pointer notation. Print the array and the values of max and min in the main program. in C++ visual studioarrow_forward
- Use C++arrow_forwardWrite a function named rockPaperScissors. It should have one input:- An array with 2 elements, each representing a player in the game of Rock Paper Scissors.It should return one output- A scalar with the result of the game.For the purposes of this program, assume the following numerical code:- 1 is rock- 2 is paper- 3 is scissorsIn the game of Rock, Paper, Scissors, rock beats scissors, paper beats rock, and scissors bears paper. Ifplayers play the same object, the result is a tie.Your output should be:- The index of the winning player if there is a winner.- 0 if there is a tie- -1 if a player played an invalid object (a number that is not 1, 2, or 3)For example, if we called our function:result = rockPaperScissors([1 2]);result would be 2, as paper beats rock.If we called our functionresult = rockPaperScissors([3 2]);result would be 1 because scissors beats papearrow_forward1- Write a user-defined function that accepts an array of integers. The function should generate the percentage each value in the array is of the total of all array values. Store the % value in another array. That array should also be declared as a formal parameter of the function. 2- In the main function, create a prompt that asks the user for inputs to the array. Ask the user to enter up to 20 values, and type -1 when done. (-1 is the sentinel value). It marks the end of the array. A user can put in any number of variables up to 20 (20 is the size of the array, it could be partially filled). 3- Display a table like the following example, showing each data value and what percentage each value is of the total of all array values. Do this by invoking the function in part 1.arrow_forward
- Write a value-returning function that receives an array of structs of the type defined below and the length of the array as parameters. It should return as the value of the function the sum of the offspring amounts in the array. Note: you do not need a main function or to create an array. Assume the array already exists from main. #include <iostream>using namespace std; // struct declaration for Animal struct Animal { // a string for animal typestring animal_type;// a string for color string color;// an integer for number of offspring. int number_of_offspring;}; // Main function to declare a structure variable of type Animal. int main(){struct Animal A1;return 0;}arrow_forwardin c++ write a code to return the value of fake coin, the fake coin is The different element of the value in the array ،and need for way solution using 1) brute force approaches 2) divide and conquer 3) decrease and conquer 4) transform and conquer and write the time of each one and what the best time of them. in c++ write a code to return the value of fake coin, the fake coin is The different element of the value in the array and be less value (minimum) , need four way solution using 1) brute force approaches 2)divide and conquer 3)decrease and conquer 4) transform and conquer and write the time of each one and what the best time of them.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





