Question

In C++ Write a function called fillArray that will fill an array of any constantly declared...

In C++ Write a function called fillArray that will fill an array of any constantly declared array size variable with random numbers in the range of 1 - 100.

Write a function called printArray that will print an array of any size.

Write a third function called countEvens which will count and return the number of even numbers in the array.

In main create an array that holds 25 ints. Use your functions to fill, print, and count the number of even numbers. You should

Fill the array

Print the array

Print the number of even numbers in the array

What not to do:

global variables

cout in any function other than main and printArray

goto statements

Please don't forget countEvens

Your output should look like the following:

xid-15584178_1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

void fillArray(int arr[], int size)
{
for (int i = 0; i < size; ++i) {
arr[i] = 1 + (rand() % 100);
}
}

void printArray(int arr[], int size)
{
cout << "Array is: ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
cout << endl;
}

int countEvens(int arr[], int size)
{
int count = 0;
for (int i = 0; i < size; ++i) {
if (arr[i] % 2 == 0) {
count++;
}
}
return count;
}

int main()
{
srand(time(NULL));
int arr[25];
fillArray(arr, 25);
printArray(arr, 25);
int evens = countEvens(arr, 25);
cout << "Number of even numbers in array is " << evens << endl;
return 0;
}

Array is: 9 20 32 29 ? 25 65 38 2 30 94 14 97 99 23 ? 3? 61 22 2 15 б3 Number of even numbers in array is 10 Process exited a

Add a comment
Know the answer?
Add Answer to:
In C++ Write a function called fillArray that will fill an array of any constantly declared...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function with two input parameters: an array of numbers and the size of the...

    Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • 17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int...

    17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers    cout << endl; // Enter the statement to print the numbers 3 and 80...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • X43: countEvens Write a function in Java that takes an int array as its parameter and...

    X43: countEvens Write a function in Java that takes an int array as its parameter and returns the number of even ints it contains. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. Complete the code bellow. Complete the code below. Use: logic conditionals if arrays loops mod public int countEvens(int[] nums) { }

  • C++ ProgrammingWrite a function that takes an integer array, the array size and a number....

    C++ ProgrammingWrite a function that takes an integer array, the array size and a number. And it determines how many times that number appears in the array. Just copy the following code and paste it to your answer. And fill the corresponding part. #include < iostream >using namespace atd; int howmany (int array lint , int number){ //Your code comes here} int main() {const int N =10; int array[N] = [11,3,2,1,3,4,6,9,1.3); int count = howlany(array,N,3);cout << 3 < "appesa" << cout << "times!"; return 0;

  • Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and...

    Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...

  • Write a function called addNeighbors that takes an array of numbers and adds each number in...

    Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next to it. The array will always have an even number of numbers in it. In the end you should return an array of neighbors added up. Please use JavaScript Instructions from your teacher. Medium Question #4 Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next...

  • This is a fill in the code type: // FILL IN THE CODE - Write a...

    This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() {   int num1;       // holds 1st number   int num2;       // holds 2nd number   int result;       // holds result of multiplication   int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number   int *num2Ptr...

  • c++, we have to write functions for the code given below and other instructions for it...

    c++, we have to write functions for the code given below and other instructions for it to compile. I am having issues understanding how to confront the problem and how to write functions and read the program so it can eventually be solved so it can be compiled 7/ * INSTRUCTIONS: Write two functions in the space // * indicated below. // * // * #1 => Find index of maximum value: Write a function that will // * find...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT