Due at the beginning of your lab section

Goals for this Pre-lab

  • Introduce you to Duet Programming

Remember to create a new directory in your repository for this lab.

$  cd CNET-cs152-spr-16
$  mkdir hw2
$ svn add hw2
$  cd hw2

Step 1: Duet Programming

Beginning in lab 2, lab time will be spent Duet Programming. Read this short introduction to Duet Programming. Create a new file in your hw2 directory named lab2questions.txt and add it to the repository. A quick way to do this is to use the unix command touch. This will create and empty file and give it a name. Then you can add it to the repository. This way, when you commit later, you don't need to remember to add it!

$ touch lab2questions.txt
$ svn add lab2questions.txt
$ vi lab2questions.txt
Now copy and paste the following questions into the file. Fill in the answers as you go through the pre-lab.

Step 2: Test-Driven Development

Next, read the wikipedia entry on Test-driven Development and answer the relevant questions in lab2questions.html.

Step 3: Read through warmup exercises

During the warmup, you are going to implement several functions that exercise control, iteration, and recursion.

In order to spend your time efficiently in lab, I have provided the skeleton files that compile, but without implementations filled in. There are three files: warmup2_main.c, warmup2.h, and warmup2.c. Read the below descriptions, then you are ready to go to lab.

Problem 1

char print_letter(unsigned int number);

Given a number, print the corresponding lower-case letter of the alphabet. The number can be anything from 0 to 25. 0 prints out 'a', 1 prints out 'b', 2 prints out 'c', etc. It also returns the character.


print_letter(5) is 'f'
print_letter(25) is 'z'

Problem 2

void print_asterisk_letter(char letter);

Given a character, print the corresponding upper-case letter of the alphabet using asterisks. The letter can be anything from 'I' to 'L'. The set of letters are here..



Problem 3

void draw_sideways_trapezoid(unsigned int width, unsigned int height);

Draw a sideways trapezoid. The width is the number of asterisks in the middle row. The number of asterisks in a row always increases by one each row until it reaches the specified width. Then, at the bottom, it also decreases by one each row until there are none.


draw_sideways_trapezoid(3,10) results in:
*
**
***
***
***
***
***
***
**
*

Problem 4

Draw a trapezoid. The width is the number of asterisks in the bottom row. Each row has two fewer asterisks than the one below it.

void draw_trapezoid(unsigned int width, unsigned int height);
draw_trapezoid(5,2) results in:

 ***
*****