Page 1 of 1

In this exercise, you will write a C++ program that will parse a text to sentences and perform a reverse operation on th

Posted: Sat Nov 27, 2021 2:20 pm
by answerhappygod
In this exercise, you will write a C++ program that will parse a
text to sentences and perform a reverse operation on them. You will
take the inputs from the console, identify each sentence in the
input and process each sentence from the last to the first and
starting from the last word to the first word. You will prompt the
word itself if the word you process is a palindrome, otherwise you
will display a message indicating the word is not a palindrome. A
palindrome is a word that reads the same backwards as forwards
(Example: ata, radar, refer, ege etc.).
NOTE: All of the code cannot be written
under the main function. There must be user-defined functions and
they must be used in the code.
Inputs and Input Checks
You only take the input text at the beginning of your program.
For this input you should follow the rules below:
- All inputs are strings.
- There can be one or more spaces or tabs between these inputs
(Hint: use a loop to take inputs).
- You can assume every sentence ends with a dot (‘.’) character
and there will be no words that contains a dot (‘.’) inside it
(i.e. "ber.ker" is not a valid word and you do not need to check
it. However, "berker." is valid because it indicates that the
sentence ends).
- Input words can contain non-alphabetical characters but they
cannot consist of only non-alphabetical characters without any
letters (i.e. "a12@341?*&BC" is a valid word but "123" is not).
- The input should contain at least one sentence.
- Empty string is not a valid input.
- The word "@" is used to notify the program that the input has
ended.
Important! You can assume that each
sentence ends with a dot in the given inputs. After each dot, there
will be a space or a new line before the next sentence or "@". So,
you must implement all the necessary checks for the inputs
described above. If there is an error in the input, your program
should display an appropriate message and ask for it again.
Processing, Program Flow and Outputs
Your program should start with a prompt that asks for the input
sentences. After a correct input is entered, your program should
calculate how many sentences the input contains and display this
information to the user. After that, your program will process the
input and eliminate non-alphabetical characters in words and
convert alphabetical characters to lowercase letters. For example
if the input string is "12Gu@LsE*n, B4aRiS8!, BErk1432eR." you need
to convert it to "gulsen baris berker.". Then, starting from the
last sentence (Hint: dots indicate the end of the sentences, so you
should use this information to parse the string) and processing
each sentence in reverse order, you need to display the word itself
if it is a palindrome, otherwise it should prompt the word
"notpalindrome". For example; if the sentence you process is "ata
ege berker radar." your program should display "radar notpalindrome
ege ata". Comparing the strings, the input check and the other
operations in the program require using some of the string member
functions (like length, find, rfind, substr, at etc.) that are
covered in class.
Important Remarks
You are expected to use functions to avoid code duplication and
improve the modularity of your program. If your main function or
any user-defined function is too long and if you do everything in
main or in another user-defined function, your exercise may not be
accepted. Please do not write everything in main and then try to
split the task into some functions just to have some functions
other than mail. This is totally against the idea of functional
design and nothing but a dirty trick. Instead please design your
program by considering the necessary functions at the
beginning. Do NOT use any global variables (variables
defined outside the functions) to avoid parameter use. You are not
allowed to use instructions such as “exit” and
“goto”. You are also not encouraged to use
“break” and “continue”.
Sample Runs
NOTE: The italic and bold phrases
are inputs taken from the user. You have to display the required
information in the same order and with the same words and
characters as below.
Sample Run 1
Please enter the input sentences: @
Input string should not be empty.
Please enter the input sentences: . @
There should be no words without alphabetical characters.
Please enter the input sentences: berker defne @
There should be at least one sentence.
Please enter the input sentences: berker 123 emre. @
There should be no words without alphabetical characters.
Please enter the input sentences: berker de1n2i3z efe. @
Sentence (1/1):
efe notpalindrome notpalindrome
Sample Run 2
Please enter the input sentences: 555 @
There should be at least one sentence.
Please enter the input sentences: 555. berker. @
There should be no words without alphabetical characters.
Please enter the input sentences: a. b. c d. e f g.
notpalindrome. yes it is:). @
Sentence (6/6): notpalindrome notpalindrome notpalindrome
Sentence (5/6): notpalindrome
Sentence (4/6): g f e
Sentence (3/6): d c
Sentence (2/6): b
Sentence (1/6): a
Sample Run 3
Please enter the input sentences: gulsen baris berker ali. . .
@
There should be no words without alphabetical characters.
Please enter the input sentences: radar giray. refer abba abcba
a bb. cs201sc is not hard. A9a#L132aA AB BA CC D. @
Sentence (4/4): d cc notpalindrome notpalindrome aalaa
Sentence (3/4): notpalindrome notpalindrome notpalindrome
cssc
Sentence (2/4): bb a abcba abba refer
Sentence (1/4): notpalindrome radar