Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Follow these detailed instructions: First, read this document in its entirety. Include the usual (detailed) comment block including program name, author, date, inputs, outputs and

image text in transcribed

Follow these detailed instructions:

First, read this document in its entirety.

Include the usual (detailed) comment block including program name, author, date, inputs, outputs and description, followed by your preprocessor directives.

An outline (Skeleton-code) of the source code is shown below and you are REQUIRED to follow this outline. Insert appropriate printf statements where needed to get the desired output. Declare and use variables as you require them. The outline has five sections where you are to enter in your code and complete the program.

Part 1: Open two files for input and read the data into two arrays (x and y). Include all appropriate error checks. You may assume that your input files will never exceed 200 floating point numbers and that both x data and y data files will be of equal length, so once you know the length of one file in the pair you can assume that the other file is of the same length.

Part 2: You are required to write the function called sum which accepts an array, and a parameter named size which indicates the size of the array. This function calculates the sum of the elements in the array and returns it to the calling function. Call this function once with the x data and once with the y data and print out the results to the screen from calling function.

Part 3: You are required to write the function call sum_prod which accepts two arrays, and a parameter named size which indicates the size of the arrays. This function calculates the sum of the product of corresponding elements in the two arrays i.e. array1[0]*array2[0]+array1[1]*array2[1]+array1[N-1]*array2[N-1]. The sum is then returned to the calling function and the result is printed to the screen.

Part 4: You are required to write the function call sum_square which accepts an array, and a parameter named size which indicates the size of the array. This function calculates the sum of the square of each array element i.e. (array1[0])2 + (array1[1])2 + (array1[N-1])2. Call this function once with the x data and once with the y data and print out the results to the screen from calling function.

EXTRA CREDIT: Part 5: Calculate the correlation coefficient, r, in main()and display the result to the screen.

OUTLINE OF THE SOURCE CODE:

#include

#include

#define SIZE 200

float sum(int size,float array1[]);

float sum_prod(int size, float array1[], float array2[]);

float sum_squared(int size, float array1[]);

int main (void)

{

//Suggested variable declarations, use more or others if you want

FILE *fp;

int i, FileLength;

float x[SIZE],y[SIZE];

//Describe code to user

//Code for part 1 goes here, open files and read in data

printf("The summation of x is:");

//call function sum sending x data and print result

printf("The summation of y is:");

//call function sum sending y data and print result

printf("The summation of xy is:");

//call function sum_prod and print result

printf("The summation of x squared is:");

//call function sum_squared sending x data and print result

printf("The summation of y squared is:");

//call function sum_squared sending y data and print result

//Extra Credit goes here

return 0;

}

float sum(int size,float array1[])

//Code for part 2 goes here

float sum_prod(int size, float array1[], float array2[])

//Code for part 3 goes here

float sum_squared(int size, float array1[])

//Code for part 4 goes here

This is a beginner coding class. Please use comments to help me understand what is going on and try not to use anything too complicated. Thank you so much!

Problem: Write a C program to find the following given two data sets, x and y N-1 N-1 N-11,2 Extra credit: Find the correlation coefficient, r, between two data sets, x and y, using the equation below: OUTPUT TABLE Sum of squares Sum of products EXTRA CREDIT:r Filename Sum datax.txt datay.txt

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

b. Will new members be welcomed?

Answered: 1 week ago