CprS 157 Schedule
CprS 157 Class 6
CprS 157 Class 8

Repetition Control Structures, Looping
Chapter 6 - Class 7

Reading Some Sample Programs

// Incomes program
// This program reads a file of income amounts classified by
// gender and computes the average income for each gender

// NotEqualCount program
// This program counts the occurrences of "!=" in a data file

These programs illustrate the use of while loops for the determination of the flow of control in a running program. Several types of terminating conditions are illustrated which will result in our exiting the loop.

Programming Exercises

  Solve these exercises in class, to your own satisfaction. When called for, create the appropriate data file and test your program on your data. Demonstrate your solutions to the instructor or to the class TA. We may save a few particularly instructive examples in the folder "Student Work" in the CprS 157 class folder on the Academic Computing file server.

Homework For Chapter 6

  Today's programming project reads data from a file about the length of certain music selections recorded on music tapes, displays a table of the data read, and calculates some summary information about the total time required on a blank tape to record all of the selections. The first task is to mimic the author's style of program design which uses block diagrams and explanatory notes to diagram the program's structure, and do this BEFORE writing any code. This systematic approach more than repays the time it takes to accomplish. The resulting program is much more likely to be clear, correct, and elegant. We will be asking for such program designs for each of our major programming projects, so now is a good time to review a few of the author's examples in our textbook and try out the technique on the present exercise. Write a clear and correct program design and C++ solution to this programming problem, and drop an electronic copy of your work into the CS157 drop box before the beginning of our next class. Personalize the results of your efforts by using our standard file-naming conventions.