Question
Write a function that counts how many times one of its parameters appears in an array. The function's prototype is int countAll(int numbers[], int size,
Write a function that counts how many times one of its parameters appears in an array. The function's prototype is
int countAll(int numbers[], int size, int target);
where numbers is the array of numbers,
size is the size of the array,
and target is the number the function is counting in the array.
For the array elts, whose elements are {1, 2, 9, 4, 1, 5, 1, 7}
countAll(elts, 8, 1) returns 3 because 1 appears 3 times in the array.
Declare the random number generator functions as global variables. Use default_random_engine and uniform_int_distribution. Use the random number generator functions and countAll to write the following functions:
Write a function that returns an array of unique random numbers. By unique, I mean that no number appears more than once in the array. The function's prototype is
void generate(int numbers[], int size)
where numbers is the array of numbers and size is the size of the array.
Write a function that returns the number of elements that appear in both arrays. The function prototype is
int countMatches(int numbers1[], int numbers2[], int size)
where we the assume that the sizes of the two arrays are greater than or equal to the second parameter size.
For the pair of arrays {7, 5, 2, 3, 1} and {2, 3, 4, 6, 1}, countMatches returns 3 and
for the pair of arrays {1, 2, 3, 5,7} and {1, 2, 3, 4, 6}, countMatches returns 3.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started