Question
HW1 Write a C++ program that generates a set of random integers and places them in an array. The number of values generated and their
HW1
Write a C++ program that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user.
The program then continually prompts the user for one of the following character commands:
a: display all the values
l: display the values less than a given value
g: display the values greater than a given value
e: display all odd values
o: display all even values
q: quit the program
An error message should be printed for an illegal command entry.
You are required to define and use the following functions:
// prints the values in the array on a single line with
// a space between each value. total gives the number of
// elements in the array
void print (int arr [], int total);
// populate places total elements in the array with random
// values between low and high inclusive
void populate (int arr [], int total, int low, int high);
// find_greater finds the elements in the array arr that
// are greater than val and places them in the array result.
// total is the number of elements in the arr array and
// result_total is the number of elements placed in the
// array result.
void find_greater (int arr [], int result [], int val,
int total, int& result_total);
// find_less finds the elements in the array arr that
// are less than val and places them in the array result.
// total is the number of elements in the arr array and
// result_total is the number of elements placed in the
// array result.
void find_less (int arr [], int result [], int val, int total,
int& result_total);
// find_odd finds the elements in the array arr that
// are odd and places them in the array result.
// total is the number of elements in the arr array and
// result_total is the number of elements placed in the
// array result.
void find_odd (int arr [], int result [], int total,
int& result_total);
// find_even finds the elements in the array arr that
// are even and places them in the array result.
// total is the number of elements in the arr array and
// result_total is the number of elements placed in the
// array result.
void find_even (int arr [], int result [], int total,
int& result_total);
The functions that you define should have the same prototypes and work as described above. Note that the find functions do not print the results. Instead they put the appropriate values in the result array. The print function can then be called to display these elements.
There will be no more than 30 elements in the in the array.
The following page has a sample run of the program (user input in bold). Your program should use the same text and spacing.
Enter the number of elements: 10
Enter the lowest possible value: -100
Enter the highest possible value: 100
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): a
-59 76 3 69 -26 -54 -79 -88 -72 43
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): g
Enter the value: 3
76 69 43
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): l
Enter the value: -40
-59 -54 -79 -88 -72
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): e
76 -26 -54 -88 -72
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): o
-59 3 69 -79 43
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): k
Must enter one of a, g, l, e, o, or q!
Enter one of a (all), g (greater), l (less), e (even), o (odd), or q (quit): q
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