CS 215 ­ Fundamentals of Programming II  Spring 2011 ­ Homework 8 20 points Out: February 16

advertisement
CS 215 ­ Fundamentals of Programming II Spring 2011 ­ Homework 8
20 points
Out: February 16
Due: February 23 (Wednesday)
This is a written homework assignment. Turn in a hardcopy (either handwritten or printed out).
1. (10 points) Write C++ statements to do the following:
(a) Declare string pointer variables named strPtr1 and strPtr2. (b) Allocate an anonymous string variable, and make strPtr1 point to it. (c) Input a string value from the keyboard and store it in the anonymous variable of part (b). (d) Display the value of the anonymous variable of part (b). (e) Cause strPtr2 to point to the anonymous variable of part (b). (f) Declare a double pointer variable named doublePtr. (g) Allow the user to enter n, the number of values to be processed; then allocate an anonymous array of n double values, and make doublePtr point to it. (h) Fill the anonymous array of part (g) with n input values, entered from the keyboard. (i) Deallocate the storage of the anonymous variable of part (b) and the anonymous array of part (g). 2. (10 points) Write C++ code fragments to do the following:
(a) Write a declaration for a pointer variable array3DPtr that will point to a dynamic 3D boolean array.
(b) Write the code for allocating storage for numRows x numCols x numDepth elements with array3DPtr pointing to the outer array.
(c) Write the code to initialize the storage allocated in (b) to be true if the sum of the indexes of an element is even and false if the sum of the indexes of an element is odd. That is, element array3DPtr[i][j][k] is true if i+j+k is even, etc.
(d) Write the code for deallocating the storage allocated in (b).
02/15/2011
Page 1 of 1
D. Hwang
Download