CIS 181 Intro to Comp Sci
Class 3, February 15, 2005

UNIX TIP OF THE DAY:

Add the following line to your .cshrc file:
bind -e

Next time you create a shell (or source your .cshrc), you will have "emacs commands" available on the unix command line. E.g., try typing <ctrl>-p at the unix prompt. You should see the previous command appear. Continue typing <ctrl>-p several times to get to earlier commands.

-----------------------------
ASSIGNMENT:

Reading: D&D, through end of Chapter 2

Exercises: p. 156 - #2.14, p. 158 - #2.18

-----------------------------
TODAY'S TOPICS

  1. A word on control structures and programming
  2. if/else selection statements. Flow charts.

    Using compound statements with if and if/else.

    Some pitfalls when using if/then selection statements.

  3. The while repetition statement

        General syntactical form

             while (condition) statement

        where statement can be null, a single statement or a compound
        statement.

        flow diagram for a while statement

        Example for home: computing the smallest and largest of five integers using a while
        statement and a counter controlled loop. See the file
        $CLASSHOME/examples/min-max5.cc

        Variations on this example --- computing the smallest and largest of
        n integers.

            (a) Example for home: Including in the data the number n of integers to read.
                See the file $CLASSHOME/examples/min-maxn.cc

                What's wrong with this program? How should it be fixed?

            (b) To be worked out in class: Reading only positive integers and using -1 as sentinel to
                signal the end of the input.
                See the file $CLASSHOME/examples/min-max-sent.cc

  4. In class example: More on sentinel controlled while loops and program design. A case study: calculating gas mileage. See the file $CLASSHOME/examples/03-miles-per-gallon.cc

    Problem 2.16 from the book. Drivers are concerned with the mileage obtained by thier automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.