Question: C++ : In this lab youll be using dynamically allocated character arrays to recreate some of the functionality of the string class. You can choose

C++ : In this lab youll be using dynamically allocated character arrays to recreate some of the functionality of the string class. You can choose whether to write this as a class or simply main() and a few functions.

Lab 4a: Creating the String

Ask the user how large a word they want to enter and then create an appropriately sized dynamically allocated character array. Once youve created the array, have the user enter their string and fill in your array letter by letter using the following code: (Youll need to replace word with whatever you called your pointer to your array.)

cout << "Please enter your word: ";

for (int i = 0; i < size; i++)

cin >> word[i];

Dont forget to deallocate (i.e. delete) the dynamically array at the end of main.

Lab 4b: Printing the String

Use array-style notation (i.e. word[i]) to create a function that will loop through your character array and print out the full string, one character at a time.

Lab 4c: Searching the String

Prompt the user for a letter to search for and then use pointer-style notation (i.e. *word) to search through your array character by character looking for the first instance of a particular letter in the string.

Lab 4d: Checking for a Palindrome

Use two pointers walking through your array to test whether your string is a palindrome or not (a palindrome reads the same forwards and backwards the 1st & last letters are the same, the 2nd & 2nd-to-last letters are the same ).

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 Databases Questions!