
CPSC 244 Project 5
Spring 2009
31 March 2009
Input/Output
ASSIGNED: 31 March 2009
DUE: 7 April 2009 (by the end of class.)
VALUE: 24 points
Overview: In this project you will complete two programming tasks; both involving writing
and reading of files. (Format your output appropriately.)
Tasks:
1. (12 points) Write a program that reads in a filename and an integer value (repre-
senting the number of values that are to be written to a file). Then:
•Open a new file with the given filename. If the file already exists, you should
print an error message and exit the program.
•Write integer values from 1 to value into the file just opened.
•Close and re-open the file filename for reading.
•Read values from the file until the END-OF-FILE is encountered, keeping the re-
quired statistics so that you can calculate the mean and standard deviation of the
data in the file.
•Print the resulting mean and standard deviation of the data in the file.
2. (12 points) Write a program that reads in a filename and five parameter values (rep-
resenting the slope and y-intercept of two lines, and the number of points, num_of, to
write to a file). Then:
•Open a new file with the given filename. If the file already exists, you should
print an error message and exit the program.
•Write num_of points for each of the two lines (whose particulars were input) into
the file just opened.
•Close and re-open the file filename for reading.
•Read point values from the file until the END-OF-FILE is encountered, keeping the
required statistics so that you can calculate the least squares line of the data in
the file.
•Print the resulting slope and y-intercept of the least squares line.
1