Question: C++ code that does the required below with separate functions and follows the requirements most important being using C-Style string using 1D arrays. Part 1:
C++ code that does the required below with separate functions and follows the requirements most important being using C-Style string using 1D arrays.


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 Tore we go, into the wild blue yonder!", then characters 'o' and '1. Program modifies the string to: Ict 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 e-string from the hear with exactly the size of the user's input string (not the maxlength 1023!!), and then reverse it Remember to clean up your heap! Example: User enters han anas program creates a new string and outputs: "4Sana nab" Example: User enters "zip":program creates a new string and outputs: "p17" 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",woll]rd343.34", and word" are the same) Suggested functions: a. char. purge string (char *str); //accepts 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 string (char *str, char* str new); //accepts 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! Implementation Requirements: Your user interface must provide clear instructions for the user and information about the data being presented Use of references or pointers is required. Use of C-style string is required Use of 1D dynamic array is required Libraries allowed to use:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
