If you want to study for the quiz, see my number systems practice web page.
By the time you have completed this lab, you should be able to:
This lab is an extension of lab05—so if you run into anything unfamiliar, review the material from lab05.
At the start of lab05, you were supposed to switch to a new pair partner. If you did so, and your partner is available again this week, please continue working with the same person.
Also keep in mind:
Choose a pilot and a navigator, and remember to switch often.
Check your PC—if you are in Cooper, there might be two mice attached. The navigator might be able to use the second mouse to help point things out, and feel a bit more connected to what is going on.
The driver should:
~pconrad/public_html/cs16/10W/labs/lab06/files/
Refer back to lab04 for clues about how to turn that directory name into a Unix command that will copy the files in to your lab06 directory. (This is the last week I'll tell you where to find that.)
Assuming you successfully completed lab05, you did the following steps:
int isOdd(int x)
; // return true if x is odd
int countOdd(int *a, int n)
; // return a count of the number of odd integers in a
Did you have the sense that you were working too hard—that it was inefficient to have to write the same function twice? I hope so—because if that thought occured to you, then you have what Larry Wall (author of Perl) calls one of the Three Virtues of a Programmer: Laziness.
Wall writes that Laziness is "the quality that makes you go to great effort to reduce overall energy expenditure."
Wouldn't it be better if the functions that we wrote and tested in the countOddWithTests.c program could be directly used in the countOddInFile.c program?
Well it turns out that we CAN do this.
Your first step this week will be to illustrate that by re-doing a step from lab05—yes, we are going to implement isOdd and countOdd one more time—but this time, we'll see that its the last time, because we'll implement it once and then reuse it in as many programs as we want.
Three of this weeks files are a re-mix of the files we saw in lab05. Together with your lab partner, take a look at each one of them:
Since testOddFunctions.c does NOT contain the function definitions for isOdd and countOdd, if we try to compile it the way we've compiled programs so far, it doesn't work. Try this yourself—you should see output like the following:
-bash-3.2$ make testOddFunctionsBut if instead, we take the compile command that make generates for us, namely:
cc testOddFunctions.c -o testOddFunctions
/tmp/ccOzuKZF.o: In function `main':
testOddFunctions.c:(.text+0xc4): undefined reference to `isOdd'
testOddFunctions.c:(.text+0xeb): undefined reference to `isOdd'
testOddFunctions.c:(.text+0x112): undefined reference to `isOdd'
testOddFunctions.c:(.text+0x139): undefined reference to `isOdd'
testOddFunctions.c:(.text+0x160): undefined reference to `isOdd'
/tmp/ccOzuKZF.o:testOddFunctions.c:(.text+0x187): more undefined references to `isOdd' follow
/tmp/ccOzuKZF.o: In function `main':
testOddFunctions.c:(.text+0x1b5): undefined reference to `countOdd'
testOddFunctions.c:(.text+0x1e3): undefined reference to `countOdd'
testOddFunctions.c:(.text+0x211): undefined reference to `countOdd'
collect2: ld returned 1 exit status
make: *** [testOddFunctions] Error 1
-bash-3.2$
cc testOddFunctions.c -o testOddFunctions
-bash-3.2$ cc oddFunctions.c testOddFunctions.c -o testOddFunctionsWe can then run the program with
-bash-3.2$
./testOddFunctions
We can also compile the countOddInFile.c
program the same way:
-bash-3.2$ cc oddFunctions.c countOddInFile.c -o countOddInFile
We can then run the program with
or with
./countOddInFile
./countOddInFile
TEST
to run the tests
Try compiling each of these programs using the command lines shown above, and running it.
What you should see is that the programs run but the tests fail.
Now, one last time, enter the correct code for isOdd and countOdd in the file oddFunctions.c in place of the stubs.
Change the code at the top of the file too, to have your name(s) (you and your pair partner(s)) and the date.
Compile and run again, using the commands from Step 2 above. Now all the tests should pass!
And, also you should be able to run the countOddInFile program on a data file, e.g.:
-bash-3.2$ ./countOddInFile nums.dat
(number of odd numbers in file appears here)
-bash-3.2$
Once you've done that, you are finished... and ready to submit—except that you need to take the quiz on numbers systems.
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:
testOddFunctions
and countOddInFile
—do the following steps:filename is up to date
testOddFunctions
and countOddInFile
, type exit to stop the recording of commands and responses into lab06.txtWhen finished, type ls one more time, and you should see a new file in your lab06 directory called lab06.txt.
Use this command to list out the contents of that file:
cat lab06.txt
If it all looks ok, you are ready to submit!
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 lab06@cs16a lab06
If you need detailed information about how turnin works, consult the instructions in lab00 through lab02.
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 19.
Late assignments will only be accepted (with 20 point penalty) through 5PM on Wednesday Feb 24th
After 5PM Wednesday Feb 24th, 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.