Lab + Homework 08 - Reverse Letters Write a program that reverses the orders of letters in words and phrases. Your program is required to
Lab + Homework 08 - Reverse Letters Write a program that reverses the orders of letters in words and phrases. Your program is required to do the following when it runs: 1) It creates an array of 100 chars, called buffer, that will be used to store a C-string. 2) The program prompts the user to enter in a line of text. 3) After the user has entered some text and pressed enter/return, the user entered characters are stored in buffer as a C-string. If the phrase or sentence exceeds the arrays capacity, only the characters that fit are stored. The rest are discarded. a. If the user pressed enter/return without entering any text, exit the program. 4) Call the ReverseLetters function to reverse the order of the characters in the C-string. 5) Display the reversed string. Requirements: 1) The program must define and call these two functions: 2) Your program must use C-strings, and not the string object defined by #include . Do not include it in your program. 3) ReverseLetters must do an in place reversal, which means another array should not be utilized to complete this task. 4) The program must exit when the user enters a blank line. Hints: 1) Remember that C-strings need to end with null terminator characters. This needs to be taken into account when calculating a C-strings length and when reversing its characters. The position of the null terminator should not be changed by reversal operation. 2) Remember that the length of the string is the number of slots a strings characters occupies within an array and that array subscripts/indexes/slots always start at [0]. void ReverseLetters(char text[]) Reverses the characters in the text C-string. It will call StringLength to get the length of the C-string int StringLength(const char text[]) Returns the length of the text C-string within the array. The length does not include the \0. CPSC 120 Week 08 3) There is not restriction on how your program handles input. You may consider using cin.getline(char[], int) instead of creating your own input handling code. 4) Unlike other function parameter types, arrays are not passed by value. This means that instead of working with an array copy, your functions have direct access to the original array via the parameter. Any changes made to the parameter are made to the array that was passed to the function. This behavior is passing my reference. 5) Even an empty C-string contains a single character, a null terminator. The \0 will be at buffer[0] when the string is empty.
Example Output:
Enter a line of text: VOTE
ETOV
Enter a line of text: Hamster
retsmaH
Enter a line of text: Careless Whisper
repsihW sseleraC
Enter a line of text: George Washington
notgnihsaW egroeG
Enter a line of text: nothing
gnihton
Enter a line of text: RACECAR
RACECAR
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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