CprS 157 Schedule
CprS 157 Class 16
CprS 157 Class 18

Multi-dimensional Arrays
Chapter 12 - Class 17






Reading Some Sample Programs


Computer programming supports both the governmental and the private sectors! Today's readings illustrate how strings and multidimensional arrays (tables) can help the programmer automate some of the operations to be found at a voting precinct.


// Election program
// This program reads votes represented by precinct number and
// ballot position from a data file, calculates the sums per
// precinct and per candidate, and writes all totals to an
// output file

The key thought is that tables of data can be modeled by multidimensional arrays. Especially important in this regard is the ability to pass such arrays to the functions that will manipulate them, so pay special attention to the programming idioms that support the declaration of arrays as variables and as formal parameters, and the method of passing an array as an argument to a function. Strings become crucial whenever words appear as data in programs. A special library of string-manipulating functions, including some with quirky names like strcmp, substr and strlen, facilitate many routine string operations.
 
 

Programming Exercises

  Solve these exercises in class, to your own satisfaction. If called for, create the appropriate data files and test your program on your data. Demonstrate your solutions to the instructor or to the class TA. There is nothing to hand in from this activity.
 
 

Homework For Chapter 12

  Modern astronomy is at the forefront of sophisticated uses of computer technology. Astronomers use computer programs not only to drive their instrumentation, but also to glean data from and enhance their pictures of the night sky. This morning's project captures a piece of this enterprise by "filtering" a star constellation out of an array of light intensity readings taken in a sector of the night sky. Follow carefully the specifications included in the statement of the problem, and then to really cap off the experience, design a data set of intensity readings which will result in a map of your favorite constellation (Southern Cross, Big Dipper, Orion, Pisces, ...). Strive for clear, elegant, and correct code. Include enough comments for a knowledgeable reader to have no difficulties in following your lines of thought. Enjoy!