Due: January 20
Problem 1: What's the point? (2 points)
Consider the code below which prints 13 3 13
double a = 3;
double b = 5;
double * d = &a;
b = *d;
// add statement here
a = 13;
cout << a << " " << b << " " << *d << endl;
What is printed if if d = &b is insert where the comment is?
Problem 2: Gemini Rising (4 points)
Write a function that "doubles" a vector by replacing every element in
the vector with two identical elements. For example, doubling
the following vector of strings
yields the vector below
| "apple" | "apple" | "orange" |
"orange" | "pear" | "pear"
|
Complete the function below the following header. For full credit you
cannot define another Vector variable, you must
double "in place" using only the parameter list. Assume
that list is full (in the example above, before doubling
list would have room for exactly three strings.)
void CloneTwo(Vector & list)
// precondition: list contains list.Length() elements, call this x
// conceptually, list = (a,b,c)
// postcondition: list contains 2*x elements,
// conceptually list = (a,a,b,b,c,c)
Problem 3: Indirect Castor and Pollux (3 points)
Rewrite your solution to Prolem 2, but assume the definition of list
changes so that it's a vector of pointers:
void CloneTwo(Vector & list)
Owen L. Astrachan
Last modified: Fri Jan 17 13:01:45 EST