CSC 161 Grinnell College Fall, 2011 Imperative Problem Solving and Data Structures

# 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:

1. using conditional statements (e.g., ` if, switch`),
2. using loops (e.g., initialization, iteration, condition testing, loop body with `for, while`), and
3. introducing motion with the Scribbler 2 robot.

## Day-by-day Details

Day Topic Preparation In-class Due Date Availability
for
Extra
Credit
Wednesday, September 7 Module 1: Conditionals, Loops, and Motion   Examples
• `quarts-2.c`
• `dance.c`
• `ice-cream-truck.c`

Friday, September 9 Types and Variables (with casting) Kernighan & Ritchie, 1.1, 2.1-2.4, 2.7 Types and Variables Lab
Monday, September 12 Conditionals, Scribbler 2
• Motion
Conditionals Lab
Tuesday, September 13 Loops Kernighan & Ritchie, 1.3, 1.4, 3.5
Examples:
• Annotated `counting-loop.c`
• Annotated `asterisk-loop.c`
Loops Lab
Wednesday, September 14 Loops and Scribbler 2 Motion Kernighan & Ritchie, 3.6-3.7 Motion and Loops Lab
Friday, September 16 Project   Robot performs looped actions and sounds Tuesday, September 20

## Some 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
• robot recalls the last two actions (current and immediately previous)
• if robot performs the same two turns in a row (e.g. two right turns), robot beeps and turns around (instead of turning the second time)
• every ten actions, robot performs a short dance three times
• at least two `if` statements
• at least three loops, of which at least one must be a `for`-loop, and at least one must be a `while` loop

Together with the program, a student pair must write a paragraph that describes what steps are needed to demonstrate the program is working correctly. Students should also recall that each of the labs in this module used a different style. Write a paragraph describing the pros and cons of each style as it helped you learn.

#### Project Submission

• The very first part of a program listing should indicate the authors of the project (use a C comment).
• The paragraph description of the project may be included in comments at the start of the program, or it may be written as a separate document.
• If the description is included in the program, please place the paragraph immediately after the authors' names.
• If the description is separate, please be sure the authors's names are at the top of the page.
• A copy of the program and description should be printed and turned in at the start of class when the project is due.
• A copy of the program and description also should be emailed to the instructor at walker@cs.grinnell.edu by the start of the class when the project is due. In the email, please include the authors' names as well as the project title in the subject line.

This project will be worth 25 points, based on the following rubric:

• control of robot activities (5 points)
• inclusion of at least two `if` statements that impact the functioning of the program (5 points)
• use of three loops (as specified) that control the program's processing (5 points)
• neatness and conciseness of code (5 points)
• paragraphs about different styles attached (5 points)

This document is available on the World Wide Web as

```http://www.cs.grinnell.edu/~walker/courses/161.fa11/module-cond-loops-testing.shtml
```

 created 24 June 2011 by Henry Walker last full revision 20 July 2011 by April O'Neill minor editing 14 September 2011 by Henry M. Walker For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.