1 |
h03 |
CS24 F19 |
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" |
h03: Chapter 3, section 3.1, Chapter 4, 4.1 - 4.5
ready? | assigned | due | points |
---|---|---|---|
true | Wed 10/09 12:00AM | Wed 10/16 11:59PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
INSTEAD OF TURNING IN THIS HOMEWORK, YOU WILL TAKE A QUIZ ON GAUCHOSPACE BY THE DUE DATE.
There is NO MAKEUP for missed homework assignments.
The quiz will be made available at least two days before the due date.
Please:
- No Staples.
- No Paperclips.
- No folded down corners.
Complete your reading of Chapter 3, section 3.1, Chapter 4, 4.1 - 4.5 (If you don’t have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).
-
1. (10 pts) What is the output of the following code:
int *p, *q;
int x;
p = &x;
q = new int;
*p = 50;
*q = 60;
cout << *p << ", " << *q << endl;
p = q;
cout << *p << ", " << *q << endl;
*p = 30;
*q = 40;
cout << *p << ", " << *q << endl;
delete p;
delete q;
after the last line of the code in the previous question, how would the behavior of the program change?
3. (10 pts) On page 98 (Chapter 3), the author talks about value semantics, which specifies different ways of copying the value of objects of a class to other objects of the same class. Using examples write two ways in which this can be done for the Complex class covered in the code at the following link: https://github.com/ucsb-cs24-mirza/cs24-m19-lectures/blob/master/lec-03/complex.cpp. This code represents a complex number (of the form re + im*i).
4. Read the code provided in pointCloud.h in point.h in this repo that describes a point and a pointCloud: https://github.com/ucsb-cs24-w18/cs24-h03. Answer the following questions about the provided code
i. (5 pts) Suppose the parametrized constructor was implemented as below, what is the syntax/logic error. Provide a correct implementation.
pointCloud::pointCloud(int cap = 10){
cloud = new point[capacity];
}
void whatsThePoint(){
pointCloud *p = new pointCloud;
for (int i = 0;i < 20; i++){
p->insert(point(i, 10*i));
}
pointCloud q(*p);
pointCloud w;
w = q;
delete p;
}