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
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