Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Write a while loop to input a series of numbers (either from a file - redirection or FILE I/O - or from the keyboard,

1) Write a while loop to input a series of numbers (either from a file - redirection or FILE I/O - or from the keyboard, but using a file will make for easier debugging) into a one dimensional array of type double named x_arr, declared to be 25 elements in length. Count the elements as you input them. Then in a second loop, a for loop this time, print out all the elements which were input. Make up your own data file for this problem. Give yourself an accomplishment point.

2) Extend your code by writing a for loop to find the largest value in the array. The largest value should go into a variable named xhigh. Your code should then print out xhigh. Give yourself an accomplishment point.

3) Extend your code by writing a for loop to find the smallest value in the array. The smallest value should go into a variable named xlow. Your code should then print out xlow. As this is essentially a repeat of the previous step, no accomplishment points for this.

4) Extend your code to produce a second array by using a for loop to iterate through your x_arr array and produce another array x_second_arr where each element in x_second_arr is 3 times the value in the arrayx_arr. Print out both arrays, with brief labelling so you can tell them apart on your output. Give yourself a minor accomplishment point.

5) You will next "normalize" the numbers in the array. This takes one array of numbers ( x_arr) and puts them into a second "normalized" array named norm_x_arr so that the original values collectively "stretch" or "contract" to fit into a different range. (Both x_arr and norm_x_arr should be declared to be the same length, for example 25.) An example of where this could be used would be to take test results between 0 and 30 ("out of 30") and produce marks between 0 and 100.

To do this, you will first input the two new limiting values you choose into two variables named max andmin - these will be your upper and lower limits of the new, normalized norm_x_arr (the 0 and 100 of the example). You then copy the code you wrote above to find the largest and the smallest values in x_arr, putting them into xhigh and xlow (these would be the 0 and 30 of the example).

Then using the appropriate loop form (give yourself a minor accomplishment point for choosing that correctly) run through the elements of x_arr, putting each element in turn into norm_x_arr modified according to the formula

normxi = min + ( ( xi - xlow ) * ( max - min ) ) / (xhigh - xlow)

to produce the second array norm_x_arr. In this formula the terms xi and normxi, are referring to single elements of the arrays x_arr and norm_x_arr. The xi will be be turned into the normxi but in the process they are adjusted so that xhigh becomes max, the maximum of all the normalized numbers, and xlowbecomes min, the minimum of all the normalized numbers ... with all elements in the xi array being adjusted proprotionally to fall between min and max.

As a trivial example, if you had the numbers 2 3 4 and you wanted to "normalize" these to between 0 and 10, you would apply the formula so that 2 3 4 would become 0 5 10. Note that the spacing between the values is maintained proportionally: 2 and 3 and 4 are all 1 apart; 0 and 5 and 10 are all 5 apart.

As another example, you could also normalize the same 2 3 4 to be between 14 and 18. 2 would become 14, 3 would become 16, and 4 would become 18.

Try this with several different sets of data. Include various orderings of the numbers (not necessarily given in sorted order), put in duplicate values for some of the data elements, and ensure your code works with a mix of positive, zero, and negative values. Give yourself a major accomplishment point.

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago