CSC 161 Grinnell College Spring, 2013 Imperative Problem Solving and Data Structures

# CSC 161 Module to Introduce Arrays, Functions, Testing, and Addresses

## Introduction

This module introduces CSC 161 students to fundamental elements of programming in C, including

1. Arrays
2. Functions and Parameters
3. Testing

## Day-by-day Details

Day Topic Preparation In-class Due Date Availability
for
Extra
Credit
Tuesday, February 12 Examples
Module 2: Arrays, Functions, Testing, Values, and Addresses
Examples:
Wednesday, February 13 Functions with simple parameters
• King: Sections 9.1-9.2, 9.4, pages 183-192, 201-202
• K&R: 1.7, 4.1-4.3
lab exercise
Friday, February 15 Arrays
• King: Section 8.1, pages 161-169
• K&R: 1.6, 1.9, 5.7
• notes on arrays
• Examples
`
lab exercise
Monday, February 18 Hour Test 1 Covers through lab on Functions with simple parameters
Tuesday, February 19 Functions with general parameters
lab exercise
Wednesday, February 20 The & Operator, Addresses, and Testing
• King: Sections 11.1-11.2, pages 241-245
• K&R: 5.1, 5.2
lab exercise
Friday, February 22 Supplemental Problem 2   Supplemental Problem 2 (done individually) Friday, February 22
Friday, February 22 Project darts.c (program with random number generator) Uninterpretable Dance Due: Wednesday, February 27

## Project: Uninterpretable Dance

Working in pairs, students should develop a program which makes the robot perform a randomized dance. That is, the program should have these features.

• The program should contain at least five dance functions, each of which instructs the robot to follow a different sequence of activities (beeps and movements) in a dance pattern.

• The main function should make at least five calls at random to the five movement functions. The functions should be executed in a different random order each time the program is run.

• The program need not ensure that each function is called at least once for any single run of the program, but all functions should have an equal probability of being called in each program execution.

• The program uses at least one function with an array parameter, a pass-by-value parameter, and a pass-by-reference parameter which is not an array. The function which uses the pass-by-reference parameter should modify the value in a significant way within the function. The function which calls that function should then be effected by the change of that variable.

• Well-written code should should be easy to read, understand, and modify. Also, the code should run efficiently. In the context of this project, therefore, your program should have these characteristics:

• There should be no redundant or unused code. For example,

• If a code segment is repeated several places, consider collecting the code in a procedure that is called as needed.
• If the same statements are repeated several times in a row, consider placing one copy of the statements in a loop.

• The code should be formatted to be easily readable. For example,

• Each procedure should have comments that describe what the procedure does (including any pre- and post-conditions).
• Comments should outline the main sections within a procedure. (It is distracting for a comment to simply repeat what the code does, but it is helpful to have a high-level comment that describes the idea behind a section of code.)
• Variable names should be descriptive. (Use variable names b1, b2, etc. only for vitamins.)
• Formatting/indenting should clarify the structure of the programs. (For example, indent consistently with in a loop and within conditional statements.)
• The code should also be reasonably efficient. For example,

• If variables i and j always have the same value, then one could be used throughout and the other discarded.
• If a value can be computed directly, do not use a loop. (No need to count to ten 1 by 1, if one can simply make the assignment value = 10.)
• If logic seems particularly complex for one section of code, consider if there is a simpler way.