Question: C + + ONLY Assignment tasks: ( 3 points ) Create a new file called pointerBasics.cpp . Write a C + + program in this
C ONLY
Assignment tasks:
points Create a new file called pointerBasics.cpp Write a
program in this new file. In this new file, write code that will do the
following:
a point Declare and assign values to variables
i Declare an integer variable called myInt and assign the
value to it
ii Declare a pointer variable called myPointer using the
dereference operator and assign it to the memory
location of myInt using the addressof operator &
b point Print to console
i Print the memory address this should be in
hexadecimal, iex format of myInt remember the
addressof operator! Then print the value contained in
the variable myPointer.
ii Print the value this should be an integer of myInt Then
print the value pointed to by myPointer Hint: remember
the dereference operator!
c point Change values and print to console
i Reassign the value of myInt from to using an
assignment operator.
ii Print the memory address this should be in
hexadecimal, iex format of myInt remember the
addressof operator! Then print the value contained in
the variable myPointer.
iii. Print the value this should be an integer of myInt Then
print the value pointed to by myPointer Hint: remember
the dereference operator!
Create a new file named arrayptrscpp and in this file, write a
program that does the following:
a Defines an array of integers called myints with a prespecified
size of
b Populates myints with input data provided by the user.
c Defines an array of pointers called myptrs of the same size as
myints and initializes the pointers in myptrs to point to
corresponding elements of the array myints refer to the "Initial
state of myptrs in the example shown below
d Sort the contents of the myptrs array in ascending order. You
are allowed to use any existing sorting algorithm two simple
options are Bubble Sort and Insertion Sort; you may use either
one or choose another one if you prefer However, you are NOT
allowed to use a library implementation of the algorithm. You
must implement the algorithm from scratch.
e What you have done above is to sort the values contained in the
myptrs array, ie you have sorted memory addresses. Now,
update your code to sort the myptrs array based on the
integers that are being pointed to ie the first element of
myptrs should point to the smallest element in myints, the
second element of myptrs should point to the next larger
element in myints, etc. refer to the "State of myptrs after
Step in the example shown below The myints array
should NOT be changed in any way; the values should stay in the
same position. You have already implemented this part of sorting
from the steps above, but that was not using pointers, so now
you need to sort it using pointers.
f Traverse the array myptrs and print the values being pointed to
by each pointer in this array.
Example:
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
