Introduction to problem solving with applications by James Tam Return to the course web page

Programs used in the lecture exercises

Program description

Download

Solution to Exercise 3: Flowchart (Sylvester and dog)

Program

Flowchart

Program trace 1: program performs some mathematical calculations that determines how big a cube grows.

Trace 1

Branching (if-else v1): program asks the user for their age and reacts differently depending whether or not the user is an adult. The program then executes an additional instruction and ends

Age: if-else

While loop that continues converting the user's human age to an equivalent cat age until the person quits the program (the in-class exercise assumed that the 'say' function could display the contents of all types of variables so there was no need to convert the numeric age to a string equivalent).

While loop

 

 

Tutorial programs

Download

Handout tutorial 4-1: Branching exercise, penguin on the ice (if-else)

PenguinIce

Handout tutorial 4-2: Branching exercise, Gum drop and a big fish (more complex if-else)

GumdropBigFish

Handout tutorial 4-3: Simple looping, clock

Clock

Extra looping example: Soccer program

Soccer

Handout tutorial 4-4: Looping and the do-together, rescue at sea

Rescue