Question: PREPARE 4.1: ALLOCATING MEMORY Write a program to: . Prompt the user for the number of characters in a string. Allocate a string of sufficient

 PREPARE 4.1: ALLOCATING MEMORY Write a program to: . Prompt the

PREPARE 4.1: ALLOCATING MEMORY Write a program to: . Prompt the user for the number of characters in a string. Allocate a string of sufficient length (one more than the number of characters!) Prompt the user for the string using getline Display the string back to the user. Release the memory and check for allocation failures. Note that since the first cin will leave the stream pointer on the newline character, you will need use cin.ignore() before getline to properly fetch the section input. Also, you must allocate the memory with new and release the memory with delete. Examples Three examples... The user input is underlined. Example1 Number of characters: 13 Enter Text: NoSpacesHere! Text: NoSpacesHere! Example 2 Number of characters: 45 Enter Text: This is a ton of Text: This is a ton of characters. How long is it? characters How long is it2 Example 3 (allocation failure) Number of characters: -10 Allocation failure! Assignment

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!