For this lab, you are welcome to get technical help from another pair on how to use or install any of the tools involved. You may also get syntax help on C. You may not, however, get help on the algorithmic portion of the exercise outside of your partner, office hours, piazza questions to TAs or instructors.
This lab is broken down into several steps:You should have already created a hw2 directory and completed the pre-lab.
Meet up with your duet programming partner for today. Log on to adjacent computers and bring up your individual accounts.
You are being asked to write four functions. Go through all steps of the Duet Programming protocol for each function, trading roles each function. You can see the function descriptions in the prelab. Decide now who is going to be the first Strategist and who is going to be the first Implementer.
scp Implementercnetid@linux.cs.uchicago.edu:~/152/hw2/warmup2.c .Then the Implementer enters his/her password.
scp Strategistcnetid@linux.cs.uchicago.edu:~/152/hw2/warmup2_main.c .
Context: Every character has an ASCII value. This means that 'a' has one value, 'b' another, 'A', another, '0' another, and so on. The exact numbers can be found in an ASCII table, though we don't care about the actual values of any of them for this exercise. These mappings of character to number are not random, but laid out specially so that you can perform useful math on them. As you probably learned from the warmup, 'a' + 5 is 'f'. Likewise, 'A' + 5 is 'F', and '0' + 5 is '5'.
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. If it receives a number larger than 26 (e.g. 153), it prints: ERROR: print_letter: Received input 153, between 0 and 25 expected. Note: Think carefully about the proper control structure and calculations to use. This can be solved in very few lines if you embrace the numerical properties of characters.
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. You must use a recursive solution.
void draw_sideways_trapezoid_rec(unsigned int width, unsigned int height);
draw_sideways_trapezoid_rec(3,10) results in:
* ** *** *** *** *** *** *** ** *
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. You must use a recursive solution.
void draw_trapezoid_rec(unsigned int width, unsigned int height);
draw_trapezoid_rec(5,2) results in:
*** *****
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. You must use an iterative solution.
void draw_sideways_trapezoid_iter(unsigned int width, unsigned int height);
draw_sideways_trapezoid_iter(3,10) results in:
* ** *** *** *** *** *** *** ** *
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. You must use an iterative solution.
void draw_trapezoid_iter(unsigned int width, unsigned int height);
draw_trapezoid_iter(5,2) results in:
*** *****
$ svn add hw2
$ svn add warmup2.h warmup2.c test_warmup2.c Makefile
$ svn commit -m "hw2 warmup complete"