Question: In this assignment, you will practice reading from files and creating, filling, and gathering information from arrays. This part is designed to be fairly simple
In this assignment, you will practice reading from files and creating, filling, and gathering information from arrays. This part is designed to be fairly simple and will make use of topics from loops and arrays alike. For this portion, you will need two arrays; one to store Booleans and one to store integers. Prompt the user for the number of elements that you want in each array (this number will be used to create both arrays and MUST be positive. Display errors and reprompt until a valid positive number is entered). Create the two arrays to have the users specified number of elements. Then, ask the user for two filenames, one that contains random integers and another that contains random Booleans. Use the values from each file to store the numbers/Booleans contained in the file in each element of their respective array. (You can assume that I will enter the file with the correct corresponding number of elements that was entered by the user. Example, if I enter a 6 for total element, I will enter two files with 6 elements - one for each array.) The Boolean array should only contain elements that hold Boolean values (true and false). The integer array should hold values from [-1000, 1000] -- I have generated two different files for each for you to test your code with. One each with 100 items and one each with 1000 items. Once filled with the values from the files, you should display the contents of the array on one line, with each elements value separated by commas and spaces (try not to display a ending comma after the last element). For the Boolean array, display the contents as well as how many elements are true, how many are false, and the index of the first true element (display -1 here, if array contains all false values). For the integer array, display the contents along with how many numbers are odd,which elements are odd (do not repeat numbers more than once, also separate with commas on one line), index of the last zero (display a -1 here, if array contains no zeros), minimum number, maximum number, sum, and what the average (mean value) of all of the elements is (displayed to exactly 3 decimal places).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
