Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / / / getWord ( ) / / / / Purpose: / / Prompt the user to enter a string / / Return string
getWord
Purpose:
Prompt the user to enter a string
Return string via output pointer parameter
Parameters:
string word pointer to a string that will contain the string the user entered
Return:
void
void getWordstring word
cout "Enter a word: ;
Add your code here that performs the cin and sets the word parameter
convertStringCharArray
Purpose:
convert the given string into an dynamically allocated array of characters
Parameters:
string word the string that has all the letters that will be used to populate the dynamic char array
char charArray output pointer to a pointer that refer to the newly allocated memory and upon return
will contain all the letters from the string word parameter null terminating character
Returns:
Length of the string not including null character
Notes:
Caller is responsible for deleting memory allocated by this function
int convertStringCharArray string word, char charArray
sizet len word.length;
Dynamically allocate memory to store all the letters from word
into a "new" array of chars
Be sure to allocate extra byte for the null string character terminator
Add your code here that uses the new operator to create a dynamic array
Add your code here that uses a for loop to copy all the letters from the word string variable
to the dynamically allocated array. Note to get full points you must use a single statement
with the pointer increment operator and the deference operator
Add your code here to add a string null terminator to the end of the dynamically allocated array
Add your code here to set the charArray output parameter
return len;
deallocateMemory
Purpose:
returns the memory used by the dynamic array produced by the convertStringCharArray function
Parameters:
char arr pointer to the dynamically allocated array
Returns:
void
remember you must use deletenot just delete when deleting dynamic arrays
void deallocateMemorychar arr
Add your code here the returns the memory referenced by the dyanamically allocated array
passed in as the arr parameter
remember the delete operator with the must be used to release memory allocated to a dynamic array
printCharArray
Purpose:
Demonstrate the use of pointer arithmetic to traverse the dynamically allocated
by printing all the characters in the array forward and backwards
Parameters:
char arr pointer to the dynamically allocated array
Returns:
void
void printCharArraychar arr
note to receive credit for this part, your code cannot use the index operator
print the contents of the array in the forward direction
char p arr;
while p
cout p;
p; move back to the last character p was previously pointing to the null terminator
cout endl;
while p arr
add your code here the prints out the characters in reverse order pointed by p
after printing the character pointed to by p decrement p to move the previous character
cout p endl; print the first character
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started