CS211b Assignment 3

Issued on: Tuesday midnight, February 6, 2007.
Due by: Tuesday midnight, February 20, 2007.

HOW TO SUBMIT

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: 3, 6 and 7) and shell interpreter sessions produced with script command (one Questions 4).

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.

QUESTION 1 (20 marks)

Let us start by a review of the notions covered during the first two weeks. For each of the following 15 actions, please, give a shell command line executing it, and test it on one example. Then, record your test runs using the script command.

QUESTION 2 (15 marks)

In this exercise, you make use of the commands tr and grep.

We assume that in our current directory we have a textfile Text which consists of words, separated by dots, blanks, commas and return characters. Each word is a sequence of lower case characters. No other characters are present in Text.

Write a sequence of shell commands (in tcsh, csh or bash) in order to perform the following actions.

QUESTION 3 (10 marks)

In this exercise, we continue our discovery of shell-scripts. Study the script unix.sh in the directory lecture-shellscripts containing the scripts used in this course.

Then, write a script containTheirNames.sh which lists all the files in the current directory that contain their names (without extension) as a subword. If you run the script containTheirNames.sh in the directory lecture-shellscripts this should list (at least) the following files:
arguments.sh  
executables.sh  
filepoke2.sh  
filepoke2.sh  
ls.sh  
multiplicationtable.sh  
removeEmptyFiles  
touch.sh  
unix.sh  
usesemicolon.sh  

QUESTION 4 (10 marks)

Use the man command to learn or review the commands ps and script.

Provide one-line Unix commands to solve each of the following tasks:

QUESTION 5 (10 marks)

Sometimes it can be frustrating to figure out where you put files. In the following questions, you are trying to find a file or files.

Use man command to learn or review the command find. Then, answer the following questions.

QUESTION 6 (25 marks)

Master Mind! Here's a very simplified version of this famous game. Player A chooses at random an integer x between 1 and 100. Player B gives successive values y1, y2, ...

Write a C program implementing this game such that a human Player B could play against the computer, Player A.

This program should allow Player B

QUESTION 7 (10 marks)

Statistics!

Write a C program performing the following actions: