Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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