|CSC 161||Grinnell College||Spring, 2012|
|Imperative Problem Solving and Data Structures|
The goal of this lab is to introduce arrays to students.
Be sure you have read the notes on arrays before you start work on this lab.
An array is used to arrange data in memory. A real-life example to this kind of data structure can be the dining hall cubbies. There are boxes next to each with limited amounts of space in each.
speed? You may want to try reasonably small errors (say index = 8) as well as ridiculous indices (say index = 123456789). Explain the results that you get.
Moving in Different Speeds
The following program, array-move.c, makes
the Scribbler move with certain speeds for certain times, which are in
the corresponding indices of their arrays. Explain how this program is
similar to and different from the program
the previous question.
numMoves, which tells the number of moves(it is now 8) to different numbers and see what happens.
Play a Song with the Help of an Array
Copy the program fragment array-notes.c, and use it to write a program which plays the song with 0.5 second notes.
The following notes outline the steps needed to utilize the Scribbler 2 to take a picture.
This is how you declare a Picture:
Picture * pic;
This is how you take and store a Picture:
pic = rTakePicture();
This is how you show a Picture
Note, however, that
rShowPicture is a blocking call;
that is, when you call
rShowPicture, the picture is displayed,
and subsequent processing is suspended until you close the picture's
When you use
rDisplayPicture, the picture is displayed,
and subsequent processing continues.
Example program photographer.c illustrates the difference of how blocking and non-blocking commands work.
photographer.c will take a picture, turn then show it to you, then repeat this twice more. However you will need to uncomment the first commented out part , then run the program and observe. Next, comment back out rShowPicture part and uncomment the second part of the code. What is the difference of the functions for these two commands?
You can make an array of Pictures just like any other variable type. This is because Picture is a "type" just like char and int, but it is for storing Scribbler pictures.
Write a program that tells the Scribbler to take and store 6 photos by turning in a circle, and showing them in reverse order. Taking the pictures and showing them should be done with two separate loops.
Development of laboratory exercises is an interative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.