Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you please help me with this simple lab activity? Thank you In this lab youll be using dynamically allocated character arrays to recreate some

Could you please help me with this simple lab activity? Thank you

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

Bonus: Converting to Pig Latin

Convert the word stored in your string into Pig Latin. You can use the following algorithm:

Add a - to the end of the string.

Find the first vowel and move all the letters before the vowel to the end of the string.

Add ay to the end of the string.

Hint: You will need to create a new larger character array to store your Pig Latin word (3 letters larger than the original).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions