Due Thursday at the beginning of your lab section

Goals for this Pre-lab

  • Familiarize yourself with the lab so you are ready to go
  • Lean about test-driven development

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

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

Step 1: Duet Programming

Beginning in lab 2, some students will spend lab time in 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 1: Test-Driven Development

Test-Driven Development is a software engineering approach that encourages developers to spend more time in concrete tasks in the planning phase in order to produce code with fewer bugs (therefore reducing debugging time). As you will no doubt find out in this class, debugging is by far the least fun part of programming. Design and implementation are far more pleasurable. So the more we can put time and energy into those phases, the less frustrating your quarter will be.

Fill in the answers as you read the wikipedia entry on Test-driven Development.

Step 2: Skeleton code

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, you need to start with a skeleton that compiles. Then you can start on development right away with the TAs there to help you. This time, I have given you the complete skeleton of one file: warmup2_main.c. I have given you a start on warmup2.h and warmup2.c, but you need to complete the skeletons prior to lab. Remember to only implement the parts necessary to make it compile.

Problem 1

char print_letter(unsigned int number);

Given a number, print the corresponding capital 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 'R', 'S', 'T', or 'U'. The set of letters are here.



Problem 3

Draw a sideways wedge recursively. The width is the number of asterisks in the first and last rows. The number of asterisks in a row always increases by one each row until it reaches the middle. Then, at the bottom, it also decreases by one each row until there is the width. You must use a recursive solution. You may write more than one function if you wish.

void draw_sideways_wedge_rec(unsigned int width, unsigned int height);
draw_sideways_wedge_rec(3,10) results in:

***
****
*****
******
*******
*******
******
*****
****
***

Problem 4

Draw a sideways wedge iteratively. The functionality is identical to draw_sideways_wedge_rec, but you may not have any function calls (other than printf) within the function.

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

Step 3: Compile your skeleton

We're going to start using a Makefile. This makes it so that you can store your compile line and not write it every time. In addition, it detects when / what files need to be recompiled (if you have a large project). Create your Makefile to compile your code.

$  touch Makefile
$  svn add Makefile
$  vi Makefile

You need a name of the target, the files on which it depends, and the exact compile line. We will name our target warmup2. Put the name of the target first, followed by a colon. Then list all of the files that, if one changes, would require recompiling the code. On the second line, you begin with a tab (not spaces) and type the exact compile line. Notice that warmup2.h is in the dependency list, but it's not in the compile line. .h files are never in the compile line.

warmup2: warmup2.c warmup2_main.c warmup2.h
	clang warmup2_main.c warmup2.c  -o warmup

Make sure that it is a tab before the word clang, not just spaces.

Now you are ready to use your Makefile!

If this is the only thing in your Makefile or if it is the first target listed, then you compile with:

$  make 

Otherwise, compile with:

$  make warmup2 
Throughout this course, we'll gradually add things to the Makefile. Pay attention - we will begin expecting you to write your own Makefile later in the course. You need to pay attention to the compile lines themselves, how to format the Makefile, and how to run the Makefile.