CS 215 ­ Fundamentals of Programming II  Fall 2013 ­ Homework 7 20 points Out: October 16, 2013

advertisement
CS 215 ­ Fundamentals of Programming II Fall 2013 ­ Homework 7
20 points
Out: October 16, 2013
Due: October 21, 2013 (Monday)
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 array2DPtr that will point to a dynamic 2D boolean array.
(b) Write the code for allocating storage for numRows x numCols elements with array2DPtr 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 array2DPtr[i][j] is true if i+j is even, etc.
(d) Write the code for deallocating the storage allocated in (b).
10/14/2013
Page 1 of 1
D. Hwang
Download