60 likes | 228 Views
Cosc 1P03. “Example is not the main thing in influencing others, it is the only thing.” Albert Schweitzer. Week 12 Lecture slides. Arrays. collections of values (objects) elements use declare create process memory model length attribute Returns the size of the array.
E N D
Cosc 1P03 “Example is not the main thing in influencing others, it is the only thing.” Albert Schweitzer Week 12 Lecture slides
Arrays • collections of values (objects) • elements • use • declare • create • process • memory model • length attribute • Returns the size of the array. • RainFall Example • Print out only those months with above average rainfall. • Palindrome Example • Strings as array of char • toCharArray & String(char[])
Processing “Variable-sized” Arrays • Example: standard deviation of student marks • data file • Array of Student objects • Array size not known • choose arbitrary size (constant) • keep count • Array organization • not all elements used • Std Dev formula:
Reading data • traversal • Student constructor • termination • no more data • no more space • error • Computing standard deviation • array as parameter • second traversal • Traversal pattern