CS16, Winter 2010

lab04: ("lab four")
More practice with material from lab03



Goals for this lab

This lab is a chance for more practice with the material from lab03.
The purpose of this lab is to help you prepare for Midterm Exam 1, and for the labs that follow.

These include:

You'll also get more practice with:

Skills Needed

By now, we expect that you are comfortable with these basic skills from lab00-lab03 so we will no longer describe them in as much detail as we did previously:

This is a pair programming lab!

Work with your assigned pair programming partner on this lab—the same one as for lab02 and lab03 (unless that person is not available).

If you do not have a pair partner, or your previously assigned partner is not available, consult the TA for your lab and/or your instructor for advice prior to starting.

 

Step by Step Instructions

Step 0a: Find your pair partner from lab02/lab03.

If he/she is available, move on to Step 1.

Step 0b: If needed, get a new pair partner

If you are still unpaired, or if your pair is more than 5 minutes late, or is absent from lab this week,
then get a new pair assignment from your TA.

Your TA will tell you who are are assigned to—or you may get your assignment by email.

Please be patient—depending on who shows up, there may have to be some slight adjustments to pair assignments.

We will try to avoid the situation where someone in a group of three, but if may be necessary depending on circumstances.

Step 0c: (Only applies if you are with a new pair partner)

If you are with a new partner, complete a new version of Worksheet W00 (print a copy from the website) and make a post to the lab04 new pair partner forum on Gauchospace.

You only need to turn in one copy per pair.

Step 1: Decide whose account you are going to work in

Remember: don't share passwords. Instead, use scp or email to share files with each other at the end of each work session. (See lab02, step 2 for details of how to use scp.)

Share your work with each other at the end of EVERY work session.

Again for emphasis, I will say it: DO NOT share passwords with each other.

Instead, use scp or email to share files with each other after every work session.

That way, if your pair partner gets hit by a bus, you can continue working without him/her—you aren't 'out of luck'.

Step 2: Do the usual preparation steps

If you've forgotten how to do the steps below, consult steps 1 and 2 from lab01.

The files for this week are at this web link:

http://www.cs.ucsb.edu/~pconrad/cs16/10W/labs/lab04/files

And can be copied with this command:

cp ~pconrad/public_html/cs16/10W/labs/lab04/files/* ~/cs16/lab04

Exam hint: Do you remember what each of these parts of this command mean? They were explained in the previous labs—and questions about this might appear on your next midterm exam:

Step 3: Review of atoi() and command line arguments

Last week we used Ch to learn about atoi() that converts from strings to integers—from type char * to type int.

We also learned about command line arguments: using argc and argv to access what a use types on the command line after the name of the program, e.g.

./makeBox 3 5

Are you and your pair partner comfortable with these ideas?


Step 4: Looking over the sample code

This week's directory contains several ASCII art programs, including the starL.c program from the previous lab, and some others from lecture:

backslash.c    printNStars.c     starBox.c      starE.c      starL.c

Take a minute to look over these and see what each of them do, and how they work.

Doing this will help you, because you'll recognize techniques you can use to solve the problems you are given below.

You may also like to run them for various values.

If you find a bug, report it to your TA and send an email to your instructor.

Step 5: Your first job: write forwardSlash.c

Using backslash.c as a model, write a program called forwardSlash.c that makes a forward slash.

In addition, add the constraint (not present in backslash.c) that the width (and equivalently the height) should be at least 2. If it isn't, produce no output.

Function call
Output
  Function call
Output
  Function call
Output
forwardSlash(0)

 
       
  forwardSlash(1)
  forwardSlash(2)
 *
*        
forwardSlash(3)

  *
 *
*
  forwardSlash(4)
   *
  *
 *
*
  forwardSlash(5)
    *
   *
  *
 *
*

The program should work for larger values of width also, not only for values up to 5.

Step 6: Your next job: write starJ.c

Using starE as a model, write a program called starJ that makes a letter J.

The bottom of the J is a full row of stars.

The back of the J (the right edge) is a full column of stars.

The front of the J (the left edge) is a column of stars that starts half way up, as shown in the examples.

The height must be an odd number that is at least 3. We will require that the width be at least three, but it can be odd or even. If the height and width are not legal values, then you should produce no output at all.

Function call
Output
  Function call
Output
  Function call
Output
starJ(6,7)

     *
     *
     *
*    *
*    *
*    *
******
       
  starJ(5,6)
  starJ(3,3)
  *
* *
***
         
starJ(4,3)
   * 
*  *
****

         
  starJ(3,7)

  *
  *
  *
* *
* *
* *
***
         
  starJ(4,5)
   *
   *
*  *
*  *
****
            
starJ(4,4)
 

         
  starJ(5,7)

    *
    *
    *
*   *
*   *
*   *
*****
         
  starJ(4,7)
   *
* * * * * * * * ****

The program should produce reasonable looking output for larger values of width and height also, provided they meet the constraints given.

Step 7: Scripting your assignment

Before doing the transcript—look over the grading rubric at the bottom of this page. Make sure you've done everything properly to maximize your grade.

In this step, we create a "transcript" of your work. We only do this after everything else is finished, and you are sure you have a good working product.

Now, to create your script:

  1. Use the proper form of the cd command to put yourself in your ~/cs16/lab04 directory (if you aren't already there)
  2. Type script lab04.txt
    You'll get back a regular looking unix prompt, but something is different now—everything you type, and everything that comes back from the computer is being recorded into a file called lab04.txt. It's like turning on the video camera.
  3. Type pwd to show what directory you are in.
  4. Type ls to show what files you have.
  5. Carefully—type rm forwardslash to remove the executable.
    • We do this so that when you use "make programName" to compile these programs during your script, we'll see the compile instead of the message "make: `programName is up to date."
    • Don't accidentally remove the .c files or you'll be starting over from scratch!)
  6. Now, type make forwardslash to compile your program. There should be no warnings and no errors.
  7. Next, run the forwardslash program for several command lines to show that it works properly. Include ones that show the "Usage" message, as well as several values that show it works.
  8. Now repeat steps 5-7 for the starJ program.

  9. Type exit to stop the recording of commands and responses into lab04.txt

When finished, type ls one more time, and you should see a new file in your lab04 directory called lab04.txt.

Use this command to list out the contents of that file:

cat lab04.txt

If it all looks ok, you are ready to submit!

Step 8. Submit your assignment using the turnin program on CSIL

To submit your assignment, you need to be in the ~/cs16 directory—one level higher than the previous step (use cd ..)

When you are in inside your cs16 directory, you are ready for the turnin step.

Type the following at the prompt:

turnin lab04@cs16a lab04

If you need detailed information about how turnin works, consult the instructions in lab00 through lab02.

Step 8. If you have more time, as a way of studying for the exam,
try the additional challenges listed below.

In lecture, we looked at some of the problems in this file:

http://www.cs.ucsb.edu/~pconrad/cs16/10W/lectures/01.28/problems.txt

Pick a couple and try them out.

Easy challenges include:

The starX is perhaps the ultimate challenge. See if you can take it on.

There are two variants. In one, we restrict width (which is equal to height) to be odd. Even widths produce no output.

Function call
Output
  Function call
Output
  Function call
Output
starX(0)

  
  starX(1)
  starX(2)
 
         
starX(3)
 * *
  *
 * *

    
  starX(4)
  
         
  starX(5)
*   *
 * *
  *
 * *
*   *
            
starX(6)
 
    
  star(7)
*     *
 *   * 
  * *
   *
  * *
 *   *
*     *
       
  star(8)
 
       

In another, we permit even widths:

Function call
Output
  Function call
Output
  Function call
Output
starX(0)

  
  starX(1)
  starX(2)
 
         
starX(3)
 * *
  *
 * *

    
  starX(4)
*  *
 **
 **
*  *
         
  starX(5)
*   *
 * *
  *
 * *
*   *
            
starX(6)
*    *
 *  *
  **
  **
 *  *
*    *        
  star(7)
*     *
 *   * 
  * *
   *
  * *
 *   *
*     *
       
  star(8)
*      *
 *    * 
  *  *
   **
   **
  *  *
 *    *
*      *
       

Another challenge is to repeat the starT program, but call it thickT, and add a third parameter for the "thickness" of the T as shown in the tables below.

A real challenge here is to figure out what the legal relationships are between height, width, and thickness that result in a reasonable looking and symmetric T. It is no longer the case that width always has to be odd, for example—it is more subtle than that, because even or odd depends on the thickness.

The minimum width and height also depend on the thickness.

Function call
Output
  Function call
Output
  Function call
Output
thickT(3,4,1)

***
 *
 *
 *  
  thickT(4,5,2)

**** **** ** ** **
  thickT(6,6,2)
******
******
  **
  **
  **
  **
    
thickT(3,2,1)
***
 *
    
  thickT(5,2,1)
*****
  *
    
  thickT(7,6,3)
*******
*******
*******
  ***
  ***
  ***


Evaluation and Grading (300 pts total)

Due Date: You should try to complete this assignment by the end of the discussion section in which it was assigned.

If you are unable to complete it by the end of your discussion section you may continue to work on it through the week—ideally before the start of next week's discussion section.

It will be accepted without late penalty until 5pm on Friday Feburary 5.

Late assignments will only be accepted (with 20 point penalty) through 5PM on Wednesday Feb 10th

After 5PM Wednesday Feb 10rd, a zero will be recorded, and the only option is to make up the points via extra credit.


Copyright 2010, Phillip T. Conrad, CS Dept, UC Santa Barbara. Permission to copy for non-commercial, non-profit, educational purposes granted, provided appropriate credit is given; all other rights reserved.