On this page:
A Brief Review of Program Design
A Sample Program Design, Phase 1
A Sample Program Design, Phase 2
A Sample Program Design, Phase 3
Code Review
6.11.0.4

2 Program Design

home work!

Purpose: The purpose of this lab is to design a complete program.

Textbook references: Chapter 6.2

A Brief Review of Program Design

5 minutes

Briefly the design of a(n interactive) program proceeds as follows: Such a program is also known as a world program in this course.
  • extract all relevant constants from the problem statement

  • determine all variable pieces; they make up the "state of the world"

  • define the necessary structure types to represent the state of the world

  • formulate data definitions for the state representation

  • pick the kind of events your main function should deal with

  • define a schematic main function with names for all necessary handler functions; don’t forget to include a signature and a purpose statement

  • make a wish list for the handler functions

Once you have the wish list of functions, you work your way thru the first two steps of the design recipe for each of them. This gives you a "working" program but nothing actually functions. Still, every time you complete one of the wishes now, something else starts to function. When all wishes are completed, your program should be up and running.

A Sample Program Design, Phase 1

15 minutes

Read the problem statement to make sure you understand all the worlds and terms.

Background Design the program play-ball. It consumes two non-negative numbers: the x and y coordinate of a ball and enables "players" to move the ball around with the arrow keys.

You pick the initial direction. The ball moves at a constant speed, which you may also pick.

The "player" can change the direction of the ball by pressing an arrow key; no other keys affect the direction of the ball. The arrow keys are interpreted in the natural manner.

At every clock tick, the ball moves along vertical and horizontal lines at the given, constant speed.

The "game" ends when the ball(’s center) is out of bounds. The program then returns the number of clock ticks that the player played.

All exercises in this lab state problems in the context of this background information.

Exercise 1 Work through the steps of the program design recipe to the point where you have a wish list.

Time to ask questions. The Head of the Lab will now take questions.

5 minutes

A Sample Program Design, Phase 2

10 minutes

Exercise 2 Work through the first two steps of the function design recipe for every function on the wish list. This should give you a program that runs but does not function.

Time to ask questions. The Head of the Lab will now take questions.

5 minutes

A Sample Program Design, Phase 3

30 minutes

Exercise 3 Design all the functions on your wish list.

Code Review

30 minutes

The Teaching Assistants will pick two pairs who will explain a solution to their lab mates following the design recipe steps.