Computer Science 145.002
Introduction to Computing for Engineers
Fall 2008 / Programming Assignment 3
“External Files & For-Loops”
Due: 7:30 AM, Thursday, October 2, 2008

In this programming assignment, you will access the data in external input files using a for-loop, accumulating all of the data that is in a user-specified file and processing it. Your program will perform the following steps:

1.  Query the user about the name of a text file that is assumed to be properly formatted, beginning with the number of ordered pairs in the file, followed by those ordered pairs of floating point numbers. Use the assert statement discussed in class to ensure that the specified file exists.

2.  After reading the number of ordered pairs from the top of the input file, use a for-loop to read all of the ordered (x, y) pairs, keeping track of five running totals:

·  The sum of all of the x-values.

·  The sum of all of the y-values.

·  The sum of all of the x2-values.

·  The sum of all of the y2-values.

·  The sum of all of the xy products.

Don’t forget to initialize each of these values to zero before the for-loop.

3.  Calculate the correlation coefficient p, using the following formula:

4.  Output the results to the user’s display, indicating whether the file’s data is linearly correlated (p ≥ 0) or not, as illustrated below.

A zipped file containing several sample text files that you may use to test your program is linked to the course Web page at http://www.cs.siue.edu/wwhite/CS145/Syllabus.htm.

Name your project PA3_Lastname where Lastname is your last name (e.g., John Doe’s project would be PA3_Doe). Don’t forget to include adequate explanatory comments in your code.

Zip-compress the entire project folder and place the zipped folder on your Moodle dropbox by 7:30 AM on Thursday, October 2, 2008.