Question: Chapter 1 0 Pointers Part 1 Create an int i with a value of 7 . Create a pointer to integer pi . Point your
Chapter Pointers
Part Create an int i with a value of Create a pointer to integer pi Point your pointer pi to your int variable i Print out your pointer, the address of your pointer and a dereference of your pointer. Create a pointer to your integer pointer ppi. Point it to your pointer to int pi Print out ppi, the address of ppi, a dereference to ppi and a double dereference to ppi.
Part Understanding deep vs shallow copy is essential for a programmer. You will get into severe problems trying to code if you do not understand it The essence of the problem is that objects, which should have independent memory storage, accidently wind up sharing memory. I want you to wrap a character array and array with abcde is strictly speaking not a string since it does not end in with a class this is just a class that contains an array and then properlyin Deep and improperly in Shallow assign memory. Make a class WrapArrayDeep that has a private pointer to char. Your default constructor should allocate an array of size You should have a copy constructor that does a deep copy. allocates a new array Your WrapArrayDeep class should start like: class WrapArrayDeep char pch; WrapArrayDeep pch new char; pch ; etc WrapArrayDeepWrapArrayDeep wad correct copy constructor. Make a similar class, WrapArrayShallow, that has an improper copy constructor that causes your copy to point to the array in the source object. instead of making a new array, have pch point to the original array Demonstrate the difference between the classes use WrapArrayDeep wadwad; for the variables holding your WrapArrayDeeps and for WrapArrayShallow: WrapArrayShallow waswas; Be sure to include a destructor in each class note it must be an ARRAY destructor put a cout in the destructor showing it was called.. In WrapArrayDeep: Use pointer arithmetic to load your array with ASCII values for letters. pca ; pca; etc. Use array notation to print your array. forint I ; I ; I cout pcai endl; In WrapArrayShallow: Use array notation to load your array with char data. pcav; pcaw; etc Use pointer arithmetic to print your array. forint I ; I ; i cout pca endl; Example Output: this program section uses variables i pi a pointer to i and ppi a pointer to pi pi EF dereference pi address of pi EF address of i EF ppi EF dereference of ppi EF address of ppi EFC double dereference of ppi this section instantiates a wrapper class for a dynamic array of elements WrapArrayDeep a b c d e WrapArrayDeep created using the copy constructor on a b c d e after changing the contents of WrapArrayDeep and ~ a b c d e Now doing the same thing with WrapArrayShallow wrapArrayShallow a b c d e wrapArrayShallow created using the copy constructor on a b c d e after changing the contents of WrapArrayShallow and ~ ~ calling destructor for WrapArrayShallow calling destructor for WrapArrayShallow this may or may not work depending on your compiler calling destructor for WrapArrayDeep calling destructor for WrapArrayDeep Press any key to continue If this crashes your program simply remove it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
