2 Program Design
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
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
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.
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.
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.