CSC 161 Module to Introduce Conditionals, Loops, and Scribbler 2 Motion
Introduction
This module introduces CSC 161 students to several fundamental elements of
programming in C, including:
- using conditional statements (e.g.,
if, switch),
- using loops (e.g., initialization, iteration, condition testing, loop
body with
for, while), and
- introducing motion with the Scribbler 2 robot.
Day-by-day Details
| Day
| Topic
| Preparation
| In-class
| Due Date
| Availability for Extra Credit
|
| Friday, January 30
| Module 001: Conditionals, Loops, and Motion
|
| Examples
|
|
|
| Monday, February 2
| Types and Variables (with casting)
|
- Reading from Text
- King: Sections 7.1-7.5, pages 125-148, OR
- Kernighan & Ritchie, 1.1, 2.1-2.4, 2.7
| Types and Variables Lab
|
|
|
| Tuesday, February 3
| Conditionals, Scribbler 2
|
| Conditionals Lab
|
|
|
| Wednesday, February 4
| Loops and Scribbler 2 Motion
|
- Reading from Text
- King: Sections 6.1-6.5, pages 99-120, OR
- Kernighan & Ritchie, 1.3, 1.4, 3.5 , 3.6-3.7
- Examples:
| Loops Lab
|
| Extra credit available if submitted by Wednesday, February 18
|
| Friday, February 6
| Supplemental Problem 1
|
| Supplemental Problem 1 (done individually)
| Friday, February 6
|
|
| Friday, February 6
| Project
|
| Robot performs looped actions and sounds
| Friday, February 13
|
|
Project Options
Working in pairs, students should develop a program that includes these
elements:
-
Program controls robot such that the robot avoids obstacles in the room.
-
If robot performs the same two turns in a row (e.g. two right turns), robot
beeps and turns for a second or two (before performing any further movements).
Notes:
-
The beep/turn around activity applies only when there are two turns,
so going forward or backward
twice in a row does not count!
-
To accomplish this requirement, you likely will need at least one variable
that keeps track of the previous robot activity. This variable is updated
after each action. After a turn left or right, this variable can be
consulted to determine if the previous move was the same type of turn.
-
Every ten actions, robot performs a short dance three times in a row (the
dance can just be a few actions).
-
Program contains at least one
if statement
-
Program contains a
switch statement or a
second if statement
-
Program contains at least three loops, at least one of which must be
a
for loop, and at least one must be a while
loop.
-
Program uses eSpeak to announce each time it turns, each time it
moves forward or backward, and each time it performs its short dance after
ten other actions.
Together with the program, a student pair must write a paragraph that
describes what steps are needed to demonstrate the program is working
correctly. That is, once the program is written, what do you need to do in
order to check it is performing properly. (This might include describing
some runs, in which obstacles are placed in the path of the robot.)
Project Submission
As with Project 000, submission of your project should come in two parts:
-
Turn in a printed copy of your code at the start of class when the project
is due.
-
Include a program listing
-
Identify what you did to test your program
-
Since this program uses the Scribbler 2 robot, it is not feasible to turn
in the output of the program (that would require a recording of the music
played)! Instead, prepare a written statement that describes the result of
testing — what happened when you ran your program, and why was that a
correct result that meets the specifications of the project?
-
Email your program to grader-161-01@cs.grinnell.edu
-
The subject line should include "CSC 161 Project 001", together with the
names of the collaborators who wrote the program.
-
Include the C program as an attachment.
Some additional guidelines follow:
-
The very first part of a program listing should indicate the authors of the
project (use a C comment).
-
The paragraph description for testing should be placed in a separate
document, outside the program.
-
Please be sure the author's names are at the top of the page.
-
The testing description should not trace what the code does, but rather
describe how the program has been tested. (Tracing the code simply repeats
the program, so an error in logic in the code would naturally just be
restated in tracing the code.)
Grading