1 |
h09 |
CS16 F16 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 9am or 10:30am |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h09: Homework 9
ready? | assigned | due | points |
---|---|---|---|
true | Tue 10/25 02:00PM | Thu 10/27 02:00PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)
Please:
- No Staples.
- No Paperclips.
- No folded down corners.
Read Chapter 5.2 thru 5.3 (If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”). Read the lecture slides for topics on binary arithmetic.
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
FOR BEST RESULTS, PRINT THIS PAGE AS A PDF, THEN PRINT THE PDF
1.(2 pts) What is the difference between a call-by-reference function and a call-by-value function? As a programmer, when might you decide to use one over the other?
2.(4 pts) Write a void-function definition for a function called “zero_both” with 2 parameters, both which are variables of type int, and sets the value of both variables to 0. Describe if you picked this function to be a call-by-reference or a call-by-value AND WHY?
3.(2 pts) What is the value of the concepts of pre-condition and post-condition to programmers?
4.(4 pts) What is test coverage and why is it important in the programming process?
5.(6 pts) What is the output of the program below (write it in the space to the right)?
#include <iostream>
using namespace std;
void phooey(int &z) {
z = z / 2;
cout << "z=" << z << endl;
}
int main() {
int b = 3;
phooey(b);
cout << "b=" << b << endl;
return 0;
}
6.(2 pts) What is the meaning of the ampersand character (&) in the code above?
7.(4 pts) Convert the following hexadecimal numbers into decimal. SHOW YOUR WORK:
66
666
BABA
2EF5
8.(12 pts) Convert the following binary numbers into octal, hexadecimal, and decimal. SHOW YOUR WORK:
10001000
101110001101
100000001010
111111101111
- (4 pts) Convert the following decimal numbers into binary. SHOW YOUR WORK:
96
253
7777
10001