Program Development
Introduction
This lab provides preliminary practice for creating a structured
program framework utliizing header files
with #include directives and simple
functions. The project for this module will provide more extensive
practice within a more creative context.
Overview
For this lab, you'll develop a program comprising the following four tasks:
tune_forward-
A sequence of beeps, involving at least 6 notes, each of which has
a specific frequency and duration. That is, tune_forward will be a
sequence of at least 6
rBeepcommands. tune_backward-
The same sequence of
rBeepcommands used fortune_forward, except in the reverse order. move_clockwise-
A sequence of Scribbler 2 movements, using a combination of at
least 3
rForwardand at least 3rTurnRightcommands. move_counter_clockwise-
The same sequence of movement commands used for move_clockwise,
except that each
rTurnRightcommand is replaced by the correspondingrTurnLeftcommand.
Note that although some tasks are related, each is largely independent from the others. Moreover, each task can be described clearly and concisely. One can think of each task conceptually at a high level, or one can delve into the lower-level details behind each task.
Although the tasks below are reasonably elementary, be sure to follow the approaches described in today's reading, including:
- placing a high-level outline within comments,
- writing stubs for procedures at an early stage of program development,
- writing code details after the high-level comments are completed,
- adding details for one procedure at a time&mdash not all at once.
Exercises
-
Copy
scale-notes.hto yourlabsdirectory. -
In your
labsdirectory, write a programprocedure-practice.cwith these features:-
Include
MyroC.handscale-notes.h(note that one uses brackets and the other uses quotes). -
Write stubs for the four separate
basic tasks outlined above (e.g.,
tune_forward). -
The
mainprogram should call each task procedure at least once at least two task procedures twice.
In writing the task procedures, be sure to write the header comments before filling in the details.
In writing the
mainfunction, write the comments first to outline the work to be done. Then add the function calls. -
Include
-
At this point, it's worth ensuring that your code actually
compiles. Use the
makecommand to build your program. (If you then run it, not much should happen.) -
Add details to the task procedures in
procedure-practice.c, one procedure at a time—practicing the problem-solving approach of incremental and iterative program development. Re-compile and then re-run your program after implementing each procedure to verify its correct syntax and operation. -
Placing details for a task within a function supports two levels of abstraction (the high-level view and the details). Further levels of abstraction are possible, when one function itself utilizes more detailed functions.
As an example, define functions
tune_forward_move_clockwise,tune_forward_move_counterclockwise,tune_backward_move_clockwise, andtune_backward_move_counterclockwise. Each procedure should:- call one previously-defined tune procedure,
- call one previously-define movement procedure, and
-
use a
printfcallto print in a terminal window the high-level description of the work being done.
-
Update your
mainprogram to call various combinations of all of these procedures. Of course, the overall outline of the work should be included within comments before the procedure calls are inserted!
