Starting from:

$25

CS201 - Home Exam 3 - Solved

Introduction
The aim of this take-home exam is to make students comfortable with loops

(while and for) and strings (operating on strings using member functions) in C++ as well as using computational approaches to solve analytical questions.

Description
In this homework, you will write a 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.).

You cannot write all of your code under the main function, i.e. you must write user-defined functions and use them.





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.

The inputs and the order of the program are explained above. It is extremely important to follow this order with the same characters since we automatically process your programs. Thus, your work will be graded as 0 unless the order is entirely correct. Please see the "Sample Runs" section for some examples.

Important Remarks
Unlike the second homework, we will not specify any functions here. But 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 grade may be lowered. 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 to get some points. Instead please design your program by considering the necessary functions at the beginning.

Try to use parametric and non-void functions wherever appropriate. Do NOT use any global variables (variables defined outside the functions) to avoid parameter use.

In this homework (and in the coming ones) you are not allowed to use instructions such as “exit” and “goto”. These cause difficulties to control the flow of your programs. Thus, we do not approve of using them. You are also not encouraged to use “break” and “continue”. The use of “break” and “continue” prevent you from forming good readable loop conditions and hence prevent you from learning how to form good loops. Think cleverly in order not to use any of these instructions. If you don't know these commands, do not even try to learn them (we will explain “break” in class).


More products