Question: Create a program that accepts keyboard input of a C - string and a search character. The C - string will be a dynamic array

Create a program that accepts keyboard input of a C-string and a search character.
The C-string will be a dynamic array that holds up to 50 characters plus the ending '\0' character.
Write this function:
char* findLastOccurrence(char*, char)
where the first parameter is a C-string and the second is the character to find in the C-string. The function returns a pointer to the last occurrence of the character to find, or it returns nullptr.
Your program may only use [] when creating and destroying the dynamic C-string.
No [] or indexes are allowed in findLastOccurrence(). Skipping using pointers to process the dynamic array will be a cheating violation.
Prove that the findLastOccurrence() function is correct by executing your solution for the first four tests. Display the characters in the input C-string that starts at the return value from the function using this format:
Ex:
Enter a string [up to 50 characters]: Hidy howdy hi ho! Enter a character to find: i The last occurrence of 'i' begins the substring of "i ho!"
Ex:
Enter a string [up to 50 characters]: My dog has lots of fleas. Enter a character to find: F 'F' does not appear in "My dog has lots of fleas."
Ex:
Enter a string [up to 50 characters]: Abracadabra Enter a character to find: a The last occurrence of 'a' begins the substring of "a"
Recall that cout and << along with a pointer to an element of a C-string (char array) correctly displays all the characters up to the ending '\0'.
The Unit Tests 5 and 6 will require that you include the header file in your solution, and then execute your program again.
Draw lots of pictures, with arrows representing the pointer variables, as you solve this problem. No one can keep track of the pointers (arrows) without drawing pictures.
here is c++ code needs to be completed.
// missing header files
// your completed program must pass tests 1 to 4 without including in your answer.
// unit tests 5 and 6 require that you include only for these tests.
// a fully correct solution will pass all 6 tests without using anything from the
// header file.
using namespace std;
// other function definition
int main()
{
// use these constants in your display of the final results
const char DOUBLE_QUOTES ='"';
const char SINGLE_QUOTE ='\'';
// create a dynamic C-string that can up to 50 characters before the ending null character '\0'
// process the dynamic C-string
// destroy the dynamic C-string to avoid memory leaks
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!