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.

NOTE: sound settings on your computer might be incorrectly set. Follow these instructions to troubleshoot if you are unable to hear the sound on your workstation, if you are using eSpeak commands.

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 rBeep commands.
tune_backward
The same sequence of rBeep commands used for tune_forward, except in the reverse order.
move_clockwise
A sequence of Scribbler 2 movements, using a combination of at least 3 rForward and at least 3 rTurnRight commands.
move_counter_clockwise
The same sequence of movement commands used for move_clockwise, except that each rTurnRight command is replaced by the corresponding rTurnLeft command.

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:

Exercises

  1. Copy scale-notes.h to your labs directory.
  2. In your labs directory, write a program procedure-practice.c with these features:
    • Include MyroC.h and scale-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 main program should call each task procedure at least once and 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 main function, write the comments first to outline the work to be done. Then add the function calls.

  3. 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.
  4. 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, and tune_backward_move_counterclockwise. Each procedure should:

    • call one previously-defined tune procedure,
    • call one previously-define movement procedure, and
    • use a printf callto print in a terminal window the high-level description of the work being done.
    Be sure each procedure has descriptive comments!
  5. Update your main program 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!