CS211b Assignment 4

Issued on: Tuesday 1:00am, February 27, 2007.
Due by: Thursday midnight, March 15, 2007.


This assignment is designed to:


For this assignment, a paper submission and an electronic submissions are required. The electronic submission consists of source programs (one for each of the following questions: 2, 3, 4 and 5). The paper submission consists of the answer to Question 1.

These source programs can be sent by email to the instructor.

As usual, you need also an assignment ticket and an submission form, to be included in an envelope together with the paper submission.

The locker of CS211b is 99 at the groundfloor of Middlesex College.


You should use the gcc compiler to compile your programs. In particular, you must compile your programs with the -Wall switch to turn on all warnings:

       gcc -Wall -o output cfile.c

If your compilation has warnings with the -Wall switch, fix them! Marks will be deducted for programs that generate warnings when compiled with -Wall. These warnings generally mean that you aren't following the rules... fixing the warnings will give you a better C program.


Your programs should contain sufficient comments that another person, familiar with the C programming language, can follow your algorithms and code. Your comments should include:

QUESTION 1 (5 marks)

Answering a question asked in class.

In C programing, the word NULL designates the null pointer.

QUESTION 2 (20 marks)

Random Latin squares.

A Latin square of order n is an n by n array such that:

Here is an example.
1 2 3
2 3 1
3 1 2

The goal of this question is to realize a C program performing the following:

Your program should contain at least three functions:

QUESTION 3 (25 marks)

A matrix editor.

The goal of this question is to realize a C program that would allow the user to perform the following actions on entering one of the characters e, d, r, q respectively:

After entering e, the user is asked

After entering r, the user is asked to enter three integer numbers i,j,v such that v becomes the new value at the intersection of Row i and Column j.

Some remarks:

Your program should contain at least three functions:

QUESTION 4 (25 marks)

An efficient trick for sorting numbers.

The goal of this question is to modify the program for sorting on Slide 12 of the chapters on arrays. Three modifications are to be implemented:

The principle of this algorithm as follows:

QUESTION 5 (25 marks)

Implementing our tr command.

The goal of this question is to realize a C program implementing a utility similar to the tr command. This new command works as follows:

By word, we mean a word in the usual sense. So we can assume that each of the strings str1, str2, str3 consists of words (taken from some dictionary) and separated by white space.