Write a C/C++ program that calculates the least squares line for two sets of values. The program consists of several functions which are described below. int ReadFile (int *, int *); Write a function that reads the contents of a text file (Data1.txt) into two separate integer arrays. The function receives two integer pointers to arrays as parameters. The contents of the text file that is attached is structured as follows: Each line in the file contains two values that are separated by a comma. The values on the left of the comma, are stored in one array and the values on the right side is stored in the other array. The number of lines that are read from the file and stored in the arrays are returned to the calling statement. Tip: a single fscanf can read into multiple variables. Ex. the statement fscanf(fp, "%s %s\n", name,surname) will read the line John Doe and save the name and surname separately. (Note the space between %s and %s indicates that there is a space in the data between the two strings to be captured) void LeastSquaresLine (int *, int *, double *, double *, int); Write a function that determines the elements a0 and a1 of the least squares line for the contents of two arrays. The function receives two integer pointers for arrays (x and y), two reference parameters for the return of a0 and a1, and the length of the arrays. The least squares line is determined as follows: See Figure 1 The function does not return any value to the calling statement. void WriteFile (double, double); Write a function that saves the formula of the least squares line to a text file. The function receives two real values for a0 and a1 after which  the formula is saved in the form y = mx + c where m = a0 and c = a1. See the example output for the file contents. See figure 2 If the file can not be opened for writing an appropriate error message is to be displayed. The function does not return any value to the calling statement. int main (); Implement the above functions in the main function to complete the program. Data1.txt(contents) 1,0 2,9 3,8 4,7 5,6 6,5 7,4 8,3 9,2 0,1

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a C/C++ program that calculates the least squares line for two sets of values. The program consists of several functions which are described below.

int ReadFile (int *, int *);

Write a function that reads the contents of a text file (Data1.txt) into two separate integer arrays. The function receives two integer pointers to arrays as parameters.

The contents of the text file that is attached is structured as follows: Each line in the file contains two values that are separated by a comma. The values on the left of the comma, are stored in one array and the values on the right side is stored in the other array.

The number of lines that are read from the file and stored in the arrays are returned to the calling statement.

Tip: a single fscanf can read into multiple variables. Ex. the statement fscanf(fp, "%s %s\n", name,surname) will read the line John Doe and save the name and surname separately. (Note the space between %s and %s indicates that there is a space in the data between the two strings to be captured)

void LeastSquaresLine (int *, int *, double *, double *, int);

Write a function that determines the elements a0 and a1 of the least squares line for the contents of two arrays. The function receives two integer pointers for arrays (x and y), two reference parameters for the return of a0 and a1, and the length of the arrays.

The least squares line is determined as follows:

See Figure 1

The function does not return any value to the calling statement.

void WriteFile (double, double);

Write a function that saves the formula of the least squares line to a text file. The function receives two real values for a0 and a1 after which  the formula is saved in the form y = mx + c where m = a0 and c = a1. See the example output for the file contents.

See figure 2

If the file can not be opened for writing an appropriate error message is to be displayed. The function does not return any value to the calling statement.

int main ();

Implement the above functions in the main function to complete the program.

Data1.txt(contents)

1,0

2,9

3,8

4,7

5,6

6,5

7,4

8,3

9,2

0,1

Given a set of N data points,
(Ti, Yi), i = 1, 2, 3, ..., N,
we can calculate the least squares line y = a0x+ai
with:
ΝΣ xy - (Σ ) (Σν)
NEx2 – (Ex)2
(Σ) (Σα') -(Σ (Σ αν)
ao
-
NE2² – (Ex)²
ΝΣ2
Transcribed Image Text:Given a set of N data points, (Ti, Yi), i = 1, 2, 3, ..., N, we can calculate the least squares line y = a0x+ai with: ΝΣ xy - (Σ ) (Σν) NEx2 – (Ex)2 (Σ) (Σα') -(Σ (Σ αν) ao - NE2² – (Ex)² ΝΣ2
Output.txt - Notepad
File Edit Format View Help
The least squares line is y=-0.030303x+4.636364
Transcribed Image Text:Output.txt - Notepad File Edit Format View Help The least squares line is y=-0.030303x+4.636364
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY