Question
CS 1336.001 Assignment 5, C++ language 1 Assignment 5 Arrays and functions Your fifth programming assignment will make use of functions and three arrays. Two
CS 1336.001 Assignment 5, C++ language
1 Assignment 5 Arrays and functions
Your fifth programming assignment will make use of functions and three arrays. Two of the arrays are parallel arrays. All three of your arrays will be of type double. The first array will contain input values. The maximum size of this array must be 100. The other two arrays will also be of type double. Each of them will have a maximum size of 20. The input array (the first array) will be read in from a file named input.txt. The second array (the limits array) will also be read in from a file. The name of the file will be limits.txt. The third array, percentages, will be the same size as the limits array. You need to count the actual number of input values read in from the input file into the input values array. If there are more than 100 values in the input file you must only read in the first 100. For the limits array you will read the values from the 2nd input file, limits.txt. You need to count the actual number of input values read in from the limits input file. If there are more than 20 limits values you must only read in the first 20. The program will process the input values. For every input value greater than or equal to limits[0] one will be added to percentage[0]. If a value is less than limits[0] but greater than or equal to limits[1] the percentage[1] value will be incremented. This will be true for all of the values in the limits array. If there were 8 limit values read in the last range to check will be limits[7] and you will count any values greater than or equal to limits[7] and less than limits[6]. If an input value is less than limits[7] they will be ignored. You will need to figure out how to code this. All of the cases except when the limits index is 0 can use the same logic, only the case where the limits index is 0 is different. When you are done you need to calculate the % of each of the values counted. You will update the elements in the percentage array to contain the percentages. The percentages will be in the range of 0.0 to 100.0. Function requirements. Main driver: You main program will be the driver, but most of the work must be done by functions. Your main function will call the read function twice. Once for the input.txt file and a second time for limits.txt. If the file was not opened by either of the read functions your main function will display an error message. CS 1336.001 Assignment 5 2 If both files were read in successfully the main will then call the build results function. Next main will call the display results function. Finally main will output the total number of input values read in by the program similar to the following: A total of 16 input values were processed Note that main must call the read function (twice) and must call the calculate results function, and the display results function. You can have additional functions if you need them. Read function: You must have a read function that will be called twice, once to read in the input values array and a second time to read in the limits array. The read function will return the number of items read in. If the number read in is 0 then either the input file was empty or the file could not be opened. Your main function must check the return value and display an error message is the value is 0. No error messages can be displayed from read function itself. The prototype for the readArray function should be similar to the following: int readArray(string inputFileName, double array[], int maxSize); You can give the function any name you want. You must return the number of values read as the return result. You must pass the input file name, array and maximum number of entries in the array, but you can pass them in a different order if you want to. You read function must check for end of file conditions and must not read in more than maxSize values into the array. Make sure you are not processing the last value I the file twice. Also make sure you are not skipping the last value in the file. These are both common errors if you are not checking for end of file properly. You may consider logic similar to the following: While (not past the end AND intputFile >> is working) { // processing } Calculate results function: You must also have a calculate results function. It will be passed in the input array, the number of values in the input array that were read in, the limits array, the percentages array, and the number of valid values in the limits array (this will also be the number of values you update in the percentages array). CS 1336.001 Assignment 5 3 Your calculate results function must initialize the percentage array values to 0.0. The number of elements to initialize to 0 is the same as the number of elements being used in the limits array. Your function will process the elements in the input array. If a value is >= the first limits element you will add 1 to the first percentages element. If the value is < the first limits element but >= to the 2nd limits element you will add 1 to the 2nd percentages element. You will do this for all of the valid limits entries. After you have processed all of the input values you need to go through the percentages elements and divide them by the number of elements being used in the limits array. That will calculate the percentage of the various ranges of values. You will also have to multiply the numbers by 100 to get the percentages into the range of 0.0 to 100.0. The calculate results function must have a return type of void. You need to pass the input array and the number of valid vales in the input array to the function. You must also pass the limits array, and the percentages array to the function. Finally you need to pass the number of value values in the limits array to the function. You can pass these 5 parameters in whatever order makes sense to your application. Display results function: Finally you will need the display results function. You need to pass the limits and percentage array to this function. You also need to pass the number of limits entries being used (this is also the number of percentages entries being used). You will then display the limits values and the percentages values in a format similar to the following: Lower Limit Percentage 90.00 25.00 80.00 12.50 70.00 12.50 60.00 6.25 50.00 12.50 0.00 31.25 Note that the percentages will not add up to 100 if some values were less than the final limit (0.0 above). Here is a sample run that would meet the output requirements: Lower Limit Percentage 90.00 25.00 80.00 12.50 70.00 12.50 60.00 6.25 50.00 12.50 0.00 31.25 A total of 16 input values were processed CS 1336.001 Assignment 5 4
Grading: Part 1 and part 2 will be graded as follows: 15% of the grade for each part will for comments you have in your program, for having meaningful variable names, and for formatting your code as is shown in the C++ text book. 85% of the grade for each part will be for the program itself. Make sure you have coded all of the required functions. Failure to do so will result in a significant loss of points. Name your source file Assignment5.cpp.
input.txt:
65.6 45.2 34.5 45.6 76.5 34.9 92.5 100.0 83.2 85.6 55.1 0.0 90.0 94.5 71.0 50.0
limits.txt
90.0 80.0 70.0 60.0 50.0 0.0
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