Question: Please do not copy and paste another Chegg answer to answer this question . C++ - Please comment in code. Keep functions under 20 lines.

Please do not copy and paste another Chegg answer to answer this question.

C++ - Please comment in code. Keep functions under 20 lines. Allowable libraries include: , , , , .

Please do not copy and paste another Chegg answer to answer thisquestion. C++ - Please comment in code. Keep functions under 20 lines.

Part 1: Text Surgeon Problem statement: You are tasked to write a program that reads in a sentence or a paragraph (max length 1023 letters) from the user, store it as a C-style string. Then the program gives the user several options for operations to perform on the text or quit. After performing an operation, the user should be prompted to select another option to operate on the original string until they select the option to quit. The program must handle all types of bad inputs from the user and recover from the errors. Detailed requirements for each choice are listed below: 1. Letter swap: the user inputs two letters, and the string is modified to replace all first letters in the text with the second letter. Example: User enters "off we go, into the wild blue yonder!", then characters 'o' and 'i'. Program modifies the string to: Iff we gi, inti the wild blue yinder! (Note: capitalization is preserved) 2. Flip (reverse) the string: For this option, you need to create a new c-string from the heap, with exactly the size of the user's input string (not the max length 1023!!), and then reverse it. Remember to clean up your heap! Example: User enters "ban ana54!"; program creates a new string and outputs: "! 45ana nab" Example: User enters "zip"; program creates a new string and outputs: "piz" 3. Words frequency: Prompt the user for an integer N, which represents for N words that the user wants to search for in the input string. Then prompt the user for these N words. Use a dynamic C++ string array allocated on the heap to store N words and output the frequency of each given words in the input string. Example: User enters This is a test sentence, is this?", then 3 words, this", "text", and "test". The program outputs: this: 2 text: 0 test: 1 (Note: Case insensitive, which means "word" and "WORD" are the same; All numbers and special characters in the string are ignored, which means wor32rd, wo]]]rd343.34, and word are the same) Suggested functions: a. char * purge_string (char *str); llaccepts a c-string, and returns a version where all numbers, spaces, and special characters removed (Note: the returned c-string must be on the heap, otherwise this c-string will be deleted once we leave this function) OR you may use this: void purge_s string (char *str, char* str_new); llaccepts two C-strings, remove all spaces and special characters in str, and store the new string into str_new *Important note: You are not allowed to convert a C-style string to a C++ string object. In other words, you have to treat the input sentence (paragraph) as a C-style string and parse through it. For frequency of given words, the N words must be entered at one time before searching to see if the words are in the sentence/paragraph. In other words, you cannot ask for a word, search its frequency and then ask for another word. You must ask for all words before searching for the words. You must use a dynamic array allocated on the heap!!! You will NOT be given credit for a variable length array, which is not dynamically allocated on the heap, i.e. string array[num_words]; is not accepted for choice 3!!!! In addition, you must not have a memory leaks (use valgrind to help)! Part 1: Text Surgeon Problem statement: You are tasked to write a program that reads in a sentence or a paragraph (max length 1023 letters) from the user, store it as a C-style string. Then the program gives the user several options for operations to perform on the text or quit. After performing an operation, the user should be prompted to select another option to operate on the original string until they select the option to quit. The program must handle all types of bad inputs from the user and recover from the errors. Detailed requirements for each choice are listed below: 1. Letter swap: the user inputs two letters, and the string is modified to replace all first letters in the text with the second letter. Example: User enters "off we go, into the wild blue yonder!", then characters 'o' and 'i'. Program modifies the string to: Iff we gi, inti the wild blue yinder! (Note: capitalization is preserved) 2. Flip (reverse) the string: For this option, you need to create a new c-string from the heap, with exactly the size of the user's input string (not the max length 1023!!), and then reverse it. Remember to clean up your heap! Example: User enters "ban ana54!"; program creates a new string and outputs: "! 45ana nab" Example: User enters "zip"; program creates a new string and outputs: "piz" 3. Words frequency: Prompt the user for an integer N, which represents for N words that the user wants to search for in the input string. Then prompt the user for these N words. Use a dynamic C++ string array allocated on the heap to store N words and output the frequency of each given words in the input string. Example: User enters This is a test sentence, is this?", then 3 words, this", "text", and "test". The program outputs: this: 2 text: 0 test: 1 (Note: Case insensitive, which means "word" and "WORD" are the same; All numbers and special characters in the string are ignored, which means wor32rd, wo]]]rd343.34, and word are the same) Suggested functions: a. char * purge_string (char *str); llaccepts a c-string, and returns a version where all numbers, spaces, and special characters removed (Note: the returned c-string must be on the heap, otherwise this c-string will be deleted once we leave this function) OR you may use this: void purge_s string (char *str, char* str_new); llaccepts two C-strings, remove all spaces and special characters in str, and store the new string into str_new *Important note: You are not allowed to convert a C-style string to a C++ string object. In other words, you have to treat the input sentence (paragraph) as a C-style string and parse through it. For frequency of given words, the N words must be entered at one time before searching to see if the words are in the sentence/paragraph. In other words, you cannot ask for a word, search its frequency and then ask for another word. You must ask for all words before searching for the words. You must use a dynamic array allocated on the heap!!! You will NOT be given credit for a variable length array, which is not dynamically allocated on the heap, i.e. string array[num_words]; is not accepted for choice 3!!!! In addition, you must not have a memory leaks (use valgrind to help)

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!