Question

Problem overview. There are a number of ways to normalize, or scale, a set of values. One common normalization technique scales the values so that the minimum value goes to 0, the maximum value goes to 1, and the other values are scaled accordingly. Using this normalization technique, the values of the array below are normalized. Original Array Values -1 -2 2 Normalized Array Values 0.25 0.01.0 0.5 The equation that computes the normalized value from a value xe in the array is the following Normalized xmin, max-min Where minyx and maxx represent the minimum and maximum values in the array x. If you substitute the minimum value for xk in the equation, the numerator is zero, thus, the normalized value for the minimum is zero. If you substitute the maximum value for x in this equation, the numerator and the denominator are the same value; hence the normalized value for the maximum is 1.0. Write and test a main program that has a one-dimensional double array. The maximum number of values that this main array can store is 25. The main program should use several programmer-defined functions. Create programmer-defined functions called get_array, display_array, array_max, array min, and norm. Prompt user to input original array values and print out normalized array values on console.
Programmer-defined function get array will read elements of and the number of values in the array as its arguments. Normalize the values in the array using the technique describe above. Use the function array_max that was developed in Chapter 5 to find out the maximum values in array x. Create function array min to find out the minimum values in array x. Assume that the function prototype if the following: void norm (double x[], int npts)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C PROGRAM:


#include<stdio.h>
void get_array(double x[],int npts)
{
int i;
double d;
printf("Enter %d elements: ",npts);
for(i=0;i<npts;i++)
{
scanf("%lf",&d);
x[i]=d;
}
}

void display_array(double x[],int npts)
{
int i;
for(i=0;i<npts;i++)
{
printf("%.2lf ",x[i]);
}
}

double array_max(double x[25],int npts)
{
int i;
double max=x[0];
for(i=1;i<npts;i++)
{
if(max<x[i])
max=x[i];
}
return(max);
}

double array_min(double x[25],int npts)
{
int i;
double min=x[0];
for(i=1;i<npts;i++)
{
if(min>x[i])
min=x[i];
}
return(min);
}
void norm(double x[25],int npts)
{
int i;
double d;
double min,max;
min=array_min(x,npts);
max=array_max(x,npts);
for(i=0;i<npts;i++)
{
d=x[i];
d=(d-min)/(max-min);
x[i]=d;
}
}

int main()
{
int npt;
double x[25];
printf("Enter number of elements (less than 25): ");
scanf("%d",&npt);
if(npt>=0 && npt<=25)
{
get_array(x,npt);
printf("\nArray elements before normalisation\n");
display_array(x,npt);
norm(x,npt);
printf("\nArray elements after normalisation\n");
display_array(x,npt);
}
else
printf("\nEntered size is not in range");
}
OUTPUT:

Enter number of elements (less than 25): 4 Enter 4 elements: -1 -2 2 0 Array elements before normalisation -1.00-2.00 2.00 0.

Add a comment
Know the answer?
Add Answer to:
Problem overview. There are a number of ways to normalize, or scale, a set of values....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a C program that: Within main, declares a linear array consisting of 10 double values....

    Create a C program that: Within main, declares a linear array consisting of 10 double values. You can assign values to the array when it is declared or fill them items manually using scanf () - your choice. Also, declare three doubles: min, max, and average. Then from within main, a function is called. The function should take a pointer to the array declared above and then finds the maximum value, the minimum value, and calculates the average of the...

  • Develop a set of static methods in a class called Array Tools that perform the functions...

    Develop a set of static methods in a class called Array Tools that perform the functions below, and overload the methods for the specified types: Description Returns the minimum value stored in an array. Array Tools Method char minimum char array[]) int minimum( int array[] ) double minimum double arrayll ) char maximum char array() ) int maximum( int array[] ) double maximum( double array[] ) Returns the maximum value stored in an array. int minimumAt( char array()) int minimumAt(...

  • Write a set of C++ programs to implement the following operations listed in the menu function...

    Write a set of C++ programs to implement the following operations listed in the menu function below. a. File: main.cpp - contains the main function b. File: arrayhw.cpp – contains the 1D array function implementations c. File: arrayhw.h – contains the 1D array function prototyped declarations d. May create other files to implement any other needed function The main menu function should display the following: Main Menu, 1D Array Functions Enter a number to choose one of the following actions:...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • In this problem you'll get to use one of Java's random number generators, java.util.Random (see the...

    In this problem you'll get to use one of Java's random number generators, java.util.Random (see the docs for Random). This class generates a random double precision number uniformly distributed in the range [0.0 ... 1.0). That is, the numbers go from 0 to 1, including 0 but excluding 1. It is a common need in Java programming to generate a random integer number that's uniformly distributed in the range of [0 ... n), such as we saw in the dice...

  • ***The following is to be written in C:**** ****The following is the sizeof.c program that needs...

    ***The following is to be written in C:**** ****The following is the sizeof.c program that needs to be modified:**** ****Section B11 the question asks to refer to:**** Modify the sizeof.c program (in the sizeof folder on github) and show the data range (min and max) in addition to the size of the data types in a nice table (print one line for each data type). Refer to section B11 in your textbook (page 257) for getting min and max values...

  • Programming 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.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...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on...

    Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on an array. These mathematical operations are calculating the minimum, maximum, sum and average values of the array. The ArrayCalc class template accepts one type parameter, which can be defined as: template <class T>. This allows ArrayCalc to carry out operations for different array data types. ArrayCalc has the following public methods, described here in pseudo code: i. void FindMin(inArrayData[], inArraySize, SoutMinVal); (This function accepts...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT