Assignments

The following table indicates assignments and due dates for Computer Science 195. Unless otherwise indicated, textbook references are to course textbooks. Additional exercises are stated later on this page. Rules for submitting programs are given at the bottom of this page.

Collaboration is allowed on some assignments and not on others; specific rules of collaboration are shown for each assignment.

Due Date Text Chapter Collaboration Problems
September 5 Gries1 No 1.3, 1.4
September 10 C Prog.1, 2 No Lab 1: Elementary C Programming
September 11 Gries2 No 2.5, 2.6cefghjkl
September 17 C Prog.1, 2 Yes Lab 2: Representation of Integers
September 25 Gries4 No 4.1.3, 4.2.6a-bjkm, 4.4.2, 4.5.2ac
Gries5 No 5.1.1ace, 5.1.2bfg, 5.2.2, 5.2.3
September 26 C Prog.1, 2 No Lab 3: Floating Point Numbers
October 2 C Prog.1, 2 No Lab 4: Functions and Parameter Passage
October 9 Gries6 No 6.2.1deg
October 17 Gries7 No 7.1acef, 7.2(1,3,5), 7.4, 7.5
Gries8 No 8.1, 8.3, 8.6
November 7 Gries9 No 9.1.1ace, 9.2.2, 9.2.3bdf, 9.2.4ace, 9.3.1ace
November 12 Gries10 No 10.1, 10.3, 10.5, 10.6, 10.8
November 19 Gries11 No 11.1, 11.8, 11.9, 11.10, 11.12
November 26 Gries14 No 14.1abd
November 28 C Prog. No Problem 1
December 3 Gries15 No 15.1.3, 15.1.4, 15.2.2
December 7 Gries16 No 16.2.2, 16.2.3
December 10 Gries16 No 16.3.1, 16.3.5, 16.3.7
December 14 Gries16 No 16.5.2, 16.5.5, 16.5.9
Due Date Text Chapter Collaboration Problems

Problem 1: Binary Search

Given integers k and n, with k < n-1, and C array a[n] of integers, and integer item. Suppose array segment a[0]..a[k] is sorted in ascending order.

Write a C-function:

```
int search (int * a, int k, int item)
```
that performs a binary search of array segment a[0]..a[k] and returns variable i satisfying the following post-condition:
```
(0 < i < k+1 < n) AND
((item = a[i]) OR ((ForAll j: 0 < j < i: a[j] < item)
AND (ForAll j: i < j < k: a[j] > item)))
```
That is, function search performs a binary search and returns variable i where either:
• item is in the array and item = a[i], or
• item is NOT in the array and i is the position in the array at which item should be inserted so the array segment would remain ordered.

Note: Your function should be iterative (not recursive), and it should be constructed so that the only return statement is at the very end and has the form return i;

Submitting Programs For This Course: In turning in any programs for the course, please follow these directions:

1. The first six lines of any C program should be comments containing your name, your mailbox number, this course number (195), and an identification of assignment being solved. For example:
```
/**************************************
* Henry M. Walker                    *
* Box Science II                     *
* Program for CSC 195                *
* Assignment for Friday, September 1 *
**************************************/
```
Also, a comment is needed for every definition of a C function, stating both pre- and post-conditions for that program unit.

2. Obtain a listing of your program and a record of relevant test runs using the submit command:
• Within a dtterm window (before running C), begin recording session with the statement

submit filename

where filename is the name of the file in which you want the session stored.
• Within the submit file,
• Print a copy of your program with the command

cat C-file.c

where C-file.c is the name of the file containing your C program.
• If your work involves several files, list the main program first with the cat command; then list any supplementary files.
• Compile your program with the gcc command, and run it with appropriate test cases to check the correctness of your program.
• When your runs are complete, stop the submit session by typing <Ctrl/D>.
• Print the record of your session by typing

print filename

3. Either write on your printout or include a separate statement that argues why your program is correct, based upon the evidence from your test runs.
• Since every programming task should yield readable and carefully tested code, the grading of all programs for this course will begin with the following algorithm (expressed in C format):
```
|| (missing pre- or post-conditions)
|| (no_evidence_of_compilation)
|| (no_test_runs)
|| (no_commentary_on_correctness))
```http://www.cs.grinnell.edu/~walker/courses/195.fa01/assignments.html