[SOLVED] CS201 - Palindrome Search in Reverse Order - Home Exam 3

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)

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.

Your take-home exams will be automatically graded using GradeChecker, so it is very important to satisfy the exact same output given in the sample runs. You can utilize GradeChecker (http://learnt.sabanciuniv.edu/GradeChecker/ ) to check whether your implementation is working in the expected way. To be able to use GradeChecker, you should upload all of your files used in the take-home exam (all your .cpp and .h files for this take-home exam). Additionally, you should submit all of your files to SUCourse (all your .cpp and .h files for this take-home exam) without zipping them. Just a reminder, you will see a character ¶ which refers to a newline in your expected output.

The name of your main source (cpp) file should be in the expected format: “SUCourseUsername_THEnumber.cpp” (all lowercase letters, e.g. gulsend_THE3.cpp). Please check the submission procedures of the take-home exam, which are listed at the end of this document.

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.

 

Sample Runs

Below, we provide some sample runs of the program that you will develop. 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 rada

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.