For this lab, you are welcome to get technical help from another student 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 office hours or piazza questions to TAs or instructors.
This lab is broken down into several steps:Homework 1, which includes warmup 1, will be collected from your subversion repository on Wednesday, April 6th, at 11:59pm.
$ cd CNET-cs152-spr-16 $ mkdir hw2 $ svn add hw2 $ cd hw2
For this lab, you may choose to participate in Duet Programming. In order to decide, you first need to learn about Duet Programming. To do so, read this short introduction to Duet Programming. Create a new file in your hw2 directory named duet.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 duet.txt $ svn add duet.txt $ vi duet.txtNow copy and paste the following questions into the file, fill in the answers, and save it. 1. There are several ways to collaborate on a project, but only one of the lines below describes collaboration with Duet Programming.
We have more accounts available, so more people can still pair up.
To check out the repository to your current location:$ svn checkout https://phoenixforge.cs.uchicago.edu/svn/cs152-spr-16-duet-XRemember to create a new directory in your repository for this lab.
$ cd cs152-spr-16-duet-X $ mkdir hw2 $ svn add hw2 $ cd hw2
You will be using the full power of repositories - repositories have two purposes: 1) backup your work in case you accidentally delete something 2) allow two people to work on different files of the same project at the same time. We will use this for both purposes.
At any given time, you should coordinate with your duet partner as to who is editing which file. Whenever your file is in a stable state (you completed something and, depending on the phases, got the compile errors out of it), you commit your file. Whenever you want to get the latest set of stable changes from your partner, you svn update.
Good luck and have fun learning together!During this warmup, you are going to implement several functions that exercise iteration and arrays. If you are using Duet Programming, do not forget to trade off after each function. The functions are ordered to provide specific practice to each student.
Draw a sideways isosceles triangle. The width is the number of asterisks that the middle row prints. Each row prints one more or one less asterisk than the previous one (depending on where it is compared to center).
void draw_sideways_triangle(unsigned int width);
draw_sideways_triangle(3) results in:
* ** *** ** *
Draw an upright isosceles triangle. The height is the number of asterisks in the middle column. Each column prints one more or one less asterisk than the one before it (depending on where it is compared to the center).
void draw_upright_triangle(unsigned int height);
draw_upright_triangle(3) results in:
* *** *****(note: The first row has 2 spaces, 1 asterisk. Second row has 1 space, 3 asterisks)
/* count_nums - count the number of instances of value in an array of size integers
*/
int count_nums(int array[], unsigned int size, int value)
Assume the following array:
int iarray[] = {6, 7, 4, 3, 5, 6, 5, 5, 4, 3, 2, 5};
count_nums(iarray, 7, 5) will return 2
count_nums(iarray, 8, 5) will return 3
count_nums(iarray, 9, 5) will return 3
count_nums(iarray, 12, 5) will return 4
This must be solved iteratively
/* last_index - returns the index of the last index of a number in an array
of size integers.
if it is not in the array, return -1 */
int last_index(int array[], unsigned int size, int value)
Assume the following array:
int iarray[] = {6, 7, 4, 3, 5, 6, 5, 5, 4, 3, 2, 5};
last_index(iarray, 6, 5) will return 4
last_index(iarray, 8, 5) will return 7
last_index(iarray, 9, 5) will return 7
last_index(iarray, 12, 5) will return 11
This must be solved iteratively
/* count_nums - count the number of instances of value in array */
int count_nums_rec(int array[], unsigned int size, int value)
This must be solved recursively
/* last_index - returns the index of the last index of a number in array*/
int last_index_rec(int array[], unsigned int size, int value)
This must be solved recursively
$ clang test_warmup2.c warmup2.c
Now get together and share your results. Work together to get the skeleton to compile and run properly. Go through the test case plan. Then commit the files.
The next time you do Phase 1, Partner A will do test case design for problem 3, and Partner B will do test case design for problem 4.
When you have completed your part of the code, update and commit.
Discussion part 1: Look at the input ranges from the black box tests. Is there separate code to handle each case? If not, are the different ranges equivalent? Also, verify that the boundaries in the input ranges match the boundaries present in the code.
Discussion part 2: Looking at student A's code, jointly develop a set of white box tests that exercise all paths in the code. If you developed more tests than the black box tests, discuss whether that code is necessary, or whether the initial tests were insufficient.
$ svn add hw2
mkdir CNET-cs152-spr-16/hw2 cp cs152-spr-16-duet-0x/hw2/* CNET-cs152-spr-16/hw2/* cd CNET-cs152-spr-16 svn add hw2
$ svn add warmup2.h warmup2.c test_warmup2.c Makefile duet.txt
$ svn commit -m "hw2 warmup complete"