Exercise #1: Write a C program that contains the following steps. Read carefully each step as they are not only programming steps but also learning topics that explain how numeric arrays in C work. Write a while loop to input a series of numbers (either from a file 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. 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. 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. 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 array x_arr. Print out both arrays, with brief labelling so you can tell them apart on your output. 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 and min - 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, 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 xlow becomes 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Exercise #1:

Write a C program that contains the following steps. Read carefully each step as they are not only programming steps but also learning topics that explain how numeric arrays in C work.

  1. Write a while loop to input a series of numbers (either from a file 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.
  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.
  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.
  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 array x_arr. Print out both arrays, with brief labelling so you can tell them apart on your output.
  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 and min - 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, 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 xlow becomes 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education