Question: Write a program with three functions. The main function will just define and initialize the variables, prompt the user for data values and call the
Write a program with three functions. The main function will just define and initialize the variables, prompt the user for data values and call the user functions. All the work will be done by the user functions. In the main function, define four double arrays of 100 elements each and initialize the arrays to zero.
The main function should prompt the user to enter the amplitude (Amp), frequency (freq) and phase of a cosine function. Read in the data and call user function #1. Then call function three and print the filled array to the screen. Do this three times fill three different arrays with cosine data. Limit the frequency between 0 to 10, and the amplitude between 0.1 and 3.0. No need to error check.
Prompt the user to enter in the amplitude of the random noise. Limit the value between 0.1 and 1.0. Read in the value and call user function #2. Then call function three and print the filled array to the screen.
Function #1: this function will be passed three float numbers, a double array and its size and return nothing. The three numbers passed to the function will be the amplitude (Amp), frequency (freq) and phase of a cosine function. Use the formula below:
x[i] = Amp * cos( freq * PI * i / 20 + phase)
Function #2: This function will be passed a float (noise amplitude), a double array and its size and return nothing. Use the formula below:
x[i] = Amplitude * (float) rand() / (float) (RAND_MAX + 1);
Function #3: Print the array to the screen. Print the array across the screen using %10.4lf formatting
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
