Due Wednesday, April 13th, 11:59pm

Goals for this Warmup

  • Introduce you to Duet Programming
  • Practice programming with iteration and arrays.

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.

Set up

Remember to create a new directory in your repository for this lab.
$  cd CNET-cs152-spr-16
$  mkdir hw2
$ svn add hw2
$  cd hw2

Duet Programming

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.txt
Now 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.
Delete all of the lines below except the one that describes Duet Programming.
a) Share a single computer, trading off who is at the keyboard
b) Work on different computers on different parts of the same problem, discussing your work at different points.
c) Take your assignment and divide it in half. One student completes one half, the other student completes the other half. You design, implement, and test independently. Once you're both done, you put the code together and submit.

2. When are good times to discuss your progress with your partner?
Delete all the lines below except the ones that are true for Duet Programming.
a) When you complete a phase of work.
b) When you are unsure how to progress.
c) Only when you have finished the entire problem.
d) When you have an idea of how your partner should solve their part of the problem.
e) When you think of a good joke to tell.

3. Which words below describe roles in Duet Programming?
(Delete the incorrect answers)
a) Function Implementer
b) Navigator
c) Driver
d) Test Implementer
e) Manager
f) Jester
g) Back-Seat Driver 4. How often should you switch roles in Duet Programming?
(Delete the incorrect answers)
a) Every 2 minutes
b) Each time you complete one phase of a single function in your assignment
b) When you complete (implementation, testing infrastructure, testing and debugging) one function in your assignment
c) Each week
d) Never

For this week, I will provide details on what each partner will do during this warmup. In future weeks, I will give fewer details. If you are not using Duet Programming, then you will need to complete *all* parts rather than only those of one partner.

Duet Programming Setup

For duet programming, you will have a separate repository. Do not forget to copy your finished files from your duet repository into your personal repository.. Your duet repository is https://phoenixforge.cs.uchicago.edu/svn/cs152-spr-16-duet-X. with your own pair number in place of X.

Pairings:
  • 0: acollins, ronaldhshi
  • 1: cloptla, ginayu
  • 2: ptgaddy, erijohnt
  • 3: shirongliu, yzpang
  • 4: jakedaniels, alexfriendman115
  • 5: schlaakja, elibogursky
  • 6: kmpeterson, pcmonaghan
  • 7: zding, nicholasuva
  • 8: sjwelber, alannawong
  • 9: gwkim, wilson97
  • 10: jacobstein, hasgrig
  • 11: mjahangoshahi, emilstein

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-X
Remember 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!

Problems:

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

Duet Programming Setup

If you are not doing Duet Programming, you may skip this step.

Phase 1: Problem Clarification, Test Design

Remember - for each file you create, "touch" it first, then add it to svn. Partner A:
1. Determine exact interfaces for functions. This has already been done for you.
2. Implement the "skeleton" files - main, .h, and .c files.
  • Create warmup2.h and place all of the function declarations in the file, along with the required preprocess commands (e.g. #ifndef).
  • Create warmup2.c and place a skeleton of each function in the file. It contains only the signature and, if it returns something, a single return statement that returns a value of the right type.
  • Create test_warmup2.c. Put in the #includes you need, the main function, and everything necessary to make a single function call to each function.
  • Update your repository to get the Makefile from your partner.
  • Compile with:
    $ clang test_warmup2.c warmup2.c
    
  • commit your results
Partner B:
  • Make a Makefile for this project. Commit it to the repository.
  • Identify the attributes to be varied for test cases in problems 1 and 2.
  • Identify ranges of valid inputs for each attribute.
  • Suggest a set of test cases that are "normal" cases, "border" cases, and "error" cases.

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.

Phase 2: Implementation

Partner A: Implement problem 1.
Partner B:
Use svn update to receive the starting code from Partner A.
Implement the test cases to problem 1. Don't forget to use good function decomposition techniques (make a function that does the testing).

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.


Phase 3: Compilation and Testing

Make sure you have both updated your files. Then you can begin compiling and testing. Whoever wrote the tests for the last group edits the main file, and whoever write the functions edits the functions file.

Roadmap

When you are finished with this phase, make sure you commit your code! Now you're ready to repeat the process with other problems.
  • Go back and complete Phases 2 and 3 on problem 2 with your roles reversed.
  • Go back to Phase 1 and make test cases for problems 3 and 4, one partner for each problem.
  • Reverse roles. Complete phases 2 and 3 with problem 3.
  • Reverse roles. Complete phases 2 and 3 with problem 4.
  • Reverse roles. Complete phases 2 and 3 with problem 4.
  • Reverse roles. Complete phases 2 and 3 with problem 5.
Good luck!

Submit

At this point, you should have done the following:
  • Checked out your repository
  • Created a folder named hw2 in your repository and run svn add hw2
    $ svn add hw2
  • Created four files and filled in the proper information: warmup2.h, warmup2.c, test_warmup2.c and Makefile inside your hw2 directory.
  • If you participated in Duet Programming, make sure you svn update your duet repository, then copy over the files into your personal repository. The cp command copies files.
    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
  • Compiled your executable manually and with the Makefile
  • Executed your code to make sure it runs properly and inspected the results.
  • $ svn commit -m "hw2 warmup complete"
Now you're ready to move on to hw2!! Remember that the homework is completed individually.