Remember to create a new directory in your repository for this lab.
$ cd CNET-cs152-win-19 $ mkdir hw2 $ svn add hw2 $ cd hw2
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 read the wikipedia entry on Test-driven Development.
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. Starting next week, you will be expected to write skeleton code prior to lab. This week, however, I have given it to you. You need to get used to the new three-file format for writing programs. Read through this section to familiarize yourself with the code and answer the questions in lab2questions.txt in preparation for lab.
From this week on, all code will be split into three files. The exact names of the files depend on the assignment. Many assignments will have two sets of files: warmup# and hw#.
File #1: assign_main.c It contains:
#include "assign.h"
Given a character, print the corresponding upper-case letter of the alphabet using asterisks. The letter can be 'S', 'T', 'U', or 'V'. The set of letters are here.
Draw a hourglass recursively. The height is the number of rows drawn. As the hourglass gets wider, it adds two asterisks each time, one to the left and one to the right of center. Once it reaches half of the height, it shrinks back down. If the height is even, there are two middle rows with the same number of asterisks.
You must use a recursive solution. You may write more than one function if you wish. In addition, note that there can be multiple sequential instructions within a recursive function. Only the simplest of functions, typically of little use, contain only one line of "work" in a recursive function. We care about the recursive design process, not the length of the resulting recursive function. However, you need to apply that recursive process on each piece of work for which it makes sense.
Place spaces on the left side of asterisks but not on the right side.
void draw_hourglass_rec(unsigned int height);
draw_hourglass_rec(9) results in:
*********
*******
*****
***
*
***
*****
*******
*********
*********
*******
*****
***
*
*
***
*****
*******
*********
Draw a hourglass iteratively. The functionality is identical to draw_hourglass_rec, but you may not have any function calls (other than printf) within the function.
void draw_hourglass_iter(unsigned int height);
draw_hourglass_iter(9) results in:
*********
*******
*****
***
*
***
*****
*******
*********
Create your Makefile to compile your code.
You need a name of the target, the files on which it depends, and the exact compile line. We will name our target warmup2.
warmup2: warmup2.c warmup2_main.c warmup2.h clang warmup2_main.c warmup2.c -o warmup2
Make sure that it is a tab before the word clang, not just spaces.
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