Use source code: Header file: Main file: In the main program, add lines of code to perform
Question:
Use source code:
Header file:
Main file:
- In the main program, add lines of code to perform the following on a dynamically allocated single instance of the class:
a) Use new to create a single instance of the class
b) Write instructions that use pointer dereferencing and dot operator to set that class instance's name and number. For example, (*ptr).setName()...
c) Write additional instructions that use the arrow operator to do the same thing as in (b). For example: ptr -> setName()...
d) print the values at each step to verify it worked.
e) use delete to return the dynamically allocated instance to the freestore. Be sure to set the pointer to NULL after that.
2. In the main program, add lines of code to perform the following on a dynamically allocated array:
a) Use new to allocate an array of 20 instances of the SmallClass class.
b) create an auxiliary (extra) pointer, set to also point at this array, so that it can be iterated (you do not want to use the original pointer, as its original base address of the array would be lost).
c) Use a for or while loop to iterate through the elements. The auxiliary pointer should be incremented at each step.
d) In the loop, use the arrow notation with the auxiliary pointer to set the number of each array element to i*2, where i is the
index of the element.
e) subsequently, print the element out so that it verifies each element was set correctly.
3. In the main program, add these lines of code based on the array:
a) Create another array pointer, such that you allocate an array having 10 more elements than the first one.
b) Copy the 20 elements from the first array to the second (the second array's last 10 would thus remain unchanged). Using standard array access with square brackets is OK.
c) Iterate through this array to print all elements out to verify that the copy of the first 20 elements worked.
After (2) and (3) are done, add lines to return the arrays to the freestore. Be sure to set recently deleted pointers to NULL!
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill