
Exercise 8 – Programming with arrays April 27, 2006
1
Exercise VIII (and last)
Exercise VIII (and last) –
–
Programming with Arrays
Programming with Arrays
Larry Caretto
Computer Science 106
Computing in Engineering
and Science
April 27, 2006
2
Outline
• Goals for exercise eight
• Specific tasks for exercise eight
• Code structure for exercise eight
3
Exercise Eight Goals
• Write program using arrays
• Write programs that computes statistical
functions of mean and standard
deviation
• Introduce concept of linear regression
as background for project three
4
Exercise Eight Task One
• Four files to download for this exercise
– Notes, task one program, task two data
file, and task two answers
• Task one program is copy and paste
– Prepare data file shown in exercise that
has five data points (xi, yi)
– Run regression program on your data file
and verify results
• View code to see how arrays are read
from data file and used in calculations
5
Exercise Eight Task One Code
• Main function only calls other functions
• Input function reads data
– Function is called in an if statement that
returns a value of true if there is no error in
data input, false otherwise
– Input returned as pass-by-reference data
• Regression function does calculations
• Output function provides output
• You can, but do not have to follow this
structure in task two
6
Input Function
• Prototype
bool getInputOK( double x[],
double y[], int& n );
• Function call
if ( !getInputOK( x, y, n) )
return EXIT_FAILURE;
• Function call returns a value of true if
the input is okay and false if it is not