1 |
h08 |
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" |
h08: Homework 8
ready? | assigned | due | points |
---|---|---|---|
true | Thu 10/20 02:00PM | Tue 10/25 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 4.6 thru 5.2 (If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).
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 are the differences between void functions and functions that return one value?
2.(3 pts) What happens if you forget the return statement in a void-function?
3.(3 pts) Can you define a function in the body of another function? And can you call a function in the body of another function?
4.(10 pts) What is the output of the program below (write it in the space to the right)?
#include <iostream>
using namespace std;
void times(int y) {
y = y * 9;
cout << "y=" << y << endl;
}
int main() {
int b = 7;
times(b);
cout << "b=" << b << endl;
return 0;
}
5.(10 pts) Suppose we have a program where the main starts with the line:
int main(int argc, char *argv[])
and the program is run with the following command line:
~jimbo/cs16/myprog 12 dozen eggs
What is the value of argc?
What is the value of argv[2]
What is the value of argv[1]
What is the value of argv[0]
What is the value of argv[1]/4?
6.(12 pts) Take the example from question 5 above. Assume that “myprog” is supposed to take in the following arguments (in order): 2 integers, a double, and a string. Write a program that (a) checks if the number of arguments used is correct (otherwise, the program puts out an error message and quits) and (b) produces an output that is the string content followed by the sum of the two integers, divided by the double. For example, if the command is:
./myprog 4 5 6.0 HumptyDumpty
,then the output would be: HumptyDumpty 1.5