CSC 115.005/006 Sonoma State University Spring 2022
Scribbler 2
CSC 115.005/006:
Programming I
Scribbler 2
Instructor: Henry M. Walker

Lecturer, Sonoma State University
Professor Emeritus of Computer Science and Mathematics, Grinnell College


Course Home References Course Details: Syllabus, Schedule, Deadlines, Topic organization MyroC Documentation Project Scope/
Acknowledgments

Notes:

Laboratory Exercise to Introduce Program Organization

This lab provides preliminary practice with a reasonably structured framework that utlizes include files and simple procedures. The project for this module will provide more extensive practice within a more creative context.


Basic tasks

For this lab, consider the following tasks:

Work Started in Class

Notes on these tasks


  1. Copy scale-notes.h to your program directory.

  2. Write a program procedure-practice-1.c with these features:

    • The program includes MyroC.h, eSpeakPackage.h and scale-notes.h.
    • The program contains stubs for separate procedures (tune_forward, tune_backward, move_clockwise, and move_counter_clockwise) for the basic tasks identified at the start of this lab.
    • 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, write the comments first to outline the work to be done. Then add the procedure calls.

  3. Add details to the task procedures in procedure-practice-1.c, one procedure at a time — illustrating the problem-solving approach of iterative program development.

Homework

Placing details for a task within a procedure supports two levels of abstraction (the high-level view and the details) Further levels of abstraction are possible, when one procedure itself utilizes more detailed procedures.


  1. Define procedures tune_forw_move_clock, tune_forw_move_counter, tune_back_move_clock, and tune_back_move_counter. Each procedure:

    • calls one previously-defined tune procedure,

    • calls one previously-define movement procedure, and

    • uses a printf procedure to print in a terminal window the high-level description of the work being done.

    Possible code for tune_forw_move_clock might be

    /*
       procedure that plays the tune forward and then moves the
       robot in a counter-clockwise pattern
     */
    void tune_forw_move_clock ()
    {
       printf ("tune forward and move clockwise\n");
       tune_forward ();
       move_clockwise ();
    }
    

    Be sure each procedure has descriptive comments!

  2. Write a main program procedure-practice-2.c that calls 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!

Although these tasks and procedures are reasonably elementary, be sure to follow the approaches described in reading for today's lab, including