1 |
h06 |
CS16 Su17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h06: Chapter 4: Predefined and programmer defined functions
ready? | assigned | due | points |
---|---|---|---|
true | Tue 07/11 02:00PM | Tue 07/18 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, sections 4.1 - 4.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”). Please note that while the book does not cover number representation, it is an important concept for this class. Questions 3 to are meant to give you more practice with number representation. These should be answered based on material presented in lectures 5 and 6.
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
-
1. (2 pts) What is a flag in a program and of what use is it?
2. (2 pts) What is type casting and how is it performed in C++?
3.(5 pts) Which of these uses of type casting will NOT ensure that f is 1.5? Answer should be (ex1), (ex2), (ex3), or (ex4) (or a combination of those).
int a(1), b(2), c(2), d(2), e(2);
double f;
f = (a + b)*c / static_cast<double>(d + e); // (ex1)
f = static_cast<double>(a + b)*c / (d + e); // (ex2)
f = (a + b)*static_cast<double>(c) / (d + e); // (ex3)
f = static_cast<double>((a + b)*(c) / (d + e)); // (ex4)
1 #include <iostream>
2 using namespace std;
3
4 bool isDivisibleBy(int a, int b);
5
6 int main() {
7 cout << "result for (15,5) is " << isDivisibleBy(5,15) << endl;
8 cout << "result for (15,5) is " << isDivisibleBy(5,15) << endl;
9 return 0;
10 }
11
12 bool isDivisibleBy(int a, int b) {
13 return ( a % b == 0 );
14 }