Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

When done, submit your completed .cpp source file in the Homework 1 area on Blackboard.

The following page has a sample run of the program (user input in bold). Your program should use the same text and spacing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions