C++ Write a program that populates an array with numbers and allows the user to run some actions on the array. Your array will be initialized in your main function to a constant global value, MAX_SIZE, which should be set to 20. To perform the subtasks, you will be writing three functions: fillArray: This function takes in an array of integers and a reference to an integer representing the number of filled elements. In this function, the user is prompred to enter a positive number that is no greater than 20, and this input will loop until the user enters a legal value. This value will be filled inside of the reference parameter mentioned above. From here, the array will be filled up to "value" elements with randomly generated numbers between 1 and 100. Make sure to set the random seed to 20 at the start of main() for consistent results. displayArray: This function takes in an array of integers and an integer representing the number of filled elements. Using a loop, all elements in the array are printed out to the user. replaceNum: This function takes in an array of integers, an integer representing the number of filled elements, an integer representing a number to replace, and one more integer that will replace the previous parameter. This function will search for the the number to replace in the array. If that number is found, then the value in the array is changed to the replacement number and the function returns true. If the number is not found, the function returns false. Your main function should first fill the array, then it should provide a looping menu interface that lets the user choose between the choices as follows: (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? Depending on the user's input, do the following actions: D: call displayArray R: Ask the user to "Enter a number to search for: " and to "Enter replacement: ". Call the replaceNum function, and if it returns true, report "Replacement sucessful." Otherwise, report "Replacement unsuccessful." F: Call fillArray. Q: Wish the user a good bye. If the user enters this, end the loop. Any other input: Report "Invalid answer - input again!" Here is one sample run of the program, with user input bolded: Enter a positive number no larger than 20: 3 (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? d 12 59 98 (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? r Enter a number to search for: 59 Enter replacement: 40 Replacement successful. (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? D 12 40 98 (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? f Enter a positive number no larger than 20: 5 (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? D 60 97 82 63 42 (D)isplay, (R)eplace, Re(F)ill, or (Q)uit? Q Good bye! Some notes: Make sure to account for both capital and lowercase input in your menu. You may write functions not mentioned here in your program, but no extra ones are required.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 1PP: (Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard...
icon
Related questions
Question
100%

C++

Write a program that populates an array with numbers and allows the user to run some actions on the array. Your array will be initialized in your main function to a constant global value, MAX_SIZE, which should be set to 20.

To perform the subtasks, you will be writing three functions:

  • fillArray: This function takes in an array of integers and a reference to an integer representing the number of filled elements. In this function, the user is prompred to enter a positive number that is no greater than 20, and this input will loop until the user enters a legal value. This value will be filled inside of the reference parameter mentioned above. From here, the array will be filled up to "value" elements with randomly generated numbers between 1 and 100. Make sure to set the random seed to 20 at the start of main() for consistent results.
  • displayArray: This function takes in an array of integers and an integer representing the number of filled elements. Using a loop, all elements in the array are printed out to the user.
  • replaceNum: This function takes in an array of integers, an integer representing the number of filled elements, an integer representing a number to replace, and one more integer that will replace the previous parameter. This function will search for the the number to replace in the array. If that number is found, then the value in the array is changed to the replacement number and the function returns true. If the number is not found, the function returns false.

Your main function should first fill the array, then it should provide a looping menu interface that lets the user choose between the choices as follows:

(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? 

Depending on the user's input, do the following actions:

  • D: call displayArray
  • R: Ask the user to "Enter a number to search for: " and to "Enter replacement: ". Call the replaceNum function, and if it returns true, report "Replacement sucessful." Otherwise, report "Replacement unsuccessful."
  • F: Call fillArray.
  • Q: Wish the user a good bye. If the user enters this, end the loop.
  • Any other input: Report "Invalid answer - input again!"

Here is one sample run of the program, with user input bolded:

Enter a positive number no larger than 20: 3
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? d
12
59
98
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? r
Enter a number to search for: 59
Enter replacement: 40
Replacement successful.
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? D
12
40
98
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? f
Enter a positive number no larger than 20: 5
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? D
60
97
82
63
42
(D)isplay, (R)eplace, Re(F)ill, or (Q)uit? Q
Good bye!

Some notes:

  • Make sure to account for both capital and lowercase input in your menu.
  • You may write functions not mentioned here in your program, but no extra ones are required.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Is there a way to do this without pointers?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning