Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Follow these detailed instructions: First, read this document in its entirety. I

ID: 3711287 • Letter: F

Question

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 <stdio.h>

#include <stdlib.h>

#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

Explanation / Answer

If you have any doubts, please give me comment... I will help you until getting solution....

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#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

fp = fopen("datax.txt", "r");

if (fp == NULL)

{

printf("Unable to open file ");

exit(1);

}

i = 0;

while (fscanf(fp, "%f", &x[i]) != -1)

i++;

FileLength = i;

fp = fopen("datay.txt", "r");

if (fp == NULL)

{

printf("Unable to open file ");

exit(1);

}

i = 0;

while (fscanf(fp, "%f", &y[i]) != -1)

i++;

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

float sum_x = sum(FileLength, x);

//call function sum sending x data and print result

printf(" %f ", sum_x);

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

//call function sum sending y data and print result

float sum_y = sum(FileLength, y);

printf(" %f ", sum_y);

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

//call function sum_prod and print result

float sum_xy = sum_prod(FileLength, x, y);

printf(" %f ", sum_xy);

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

//call function sum_squared sending x data and print result

float sum_squared_x = sum_squared(FileLength, x);

printf(" %f ", sum_squared_x);

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

//call function sum_squared sending y data and print result

float sum_squared_y = sum_squared(FileLength, y);

printf(" %f ", sum_squared_y);

//Extra Credit goes here

float r = (FileLength * sum_xy - sum_x*sum_y)/(sqrt((FileLength*sum_squared_x)-(sum_x*sum_x))-sqrt((FileLength*sum_squared_y)-(sum_y*sum_y)));

printf("Correlation coefficient r = %f ", r);

return 0;

}

float sum(int size, float array1[])

{

//Code for part 2 goes here

float sum = 0;

int i = 0;

for (i = 0; i < size; i++)

{

sum += array1[i];

}

return sum;

}

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

{

//Code for part 3 goes here

float sum = 0;

int i = 0;

for (i = 0; i < size; i++)

{

sum += array1[i] * array2[i];

}

return sum;

}

float sum_squared(int size, float array1[])

{

//Code for part 4 goes here

float sum = 0;

int i=0;

for(i=0; i<size; i++){

sum += (array1[i]*array1[i]);

}

return sum;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote