In this assignment you will use the MyString class that you wrote earlier in this course. A palindrome is a string that reads the same forward and backward. Write a program that reads in any number of MyStrings from the user and determines if each MyString is a palindrome. The user will terminate each MyString by pressing the return (or enter) button. The user will indicate that there are no more MyStrings by entering "quit". To do this you must write a recursive function named isAPalindrome that takes a single MyString argument and two arguments that are bounds on MyString indices. The function must examine the part of the argument between the two bounds (including the bounds) and return true if this part of the argument is a palindrome, false if it is not a palindrome. The function must be recursive and must not call any other functions except ispunct(), isspace(), and toupper() (described below). Do not make any changes to the MyString class (except, if necessary, to correct errors in your MyString class). In particular, note that the isAPalindrome() function is not part of the MyString class. Your client file, main.cpp, will contain your main() function and your isAPalindrome() function. Do not use the C++ string class or arrays or vectors or any other container other than MyString. Follow this sample output closely: Enter a string: Able was I, ere I saw Elba Able was I, ere I saw Elba is a palindrome. Enter a string: peanut butter peanut butter is not a palindrome. Enter a string: quit In determining whether a string is a palindrome, this function must consider uppercase and lowercase letters to be the same and ignore punctuation characters and whitespace characters. You must not modify the argument in any way or make a copy of the argument to accomplish this. The simplest way to handle uppercase/lowercase issues is to make everything uppercase on the fly, right at the instant that you are comparing the two characters. Full documentation is required. Hints: • You will want to use three functions that are in the cctype library (i.e. you must #include cctype to use them). They are ispunct(char), a bool function which returns true if its argument is a punctuation mark and false otherwise, isspace(char), which returns true if its argument is a whitespace character and false otherwise, and toupper(char), which returns the uppercase equivalent of its argument (without changing the argument itself). • I strongly suggest that you first write this program so that it works in the general case (i.e. assuming that all letters are uppercase and no characters are punctuation characters or whitespace characters), and then add code to handle the uppercase/lowercase and punctuation/whitespace issues. • • • Make sure you try a palindrome that starts and ends with the same letter but is not a palindrome. Returning a false positive in this case is one of the most common errors that students make. Another common error is calling this value-returning function as if it was a void function. You can't say "isAPalindrome (str1, leftBound, highBound);" on a line by itself. It doesn't do anything. Also, make sure that every case in your function has a return statement. Often students submit programs that worked perfectly for them, but they were just getting lucky, and the computer was returning the correct value by chance when there was no return statement. • If leftBound > rightBound, that means that the MyString under consideration is the empty string. An empty string reads the same forward and backward, so it is a palindrome.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

Write the full C++ code for main.cpp, mystring.h, and mystring.cpp

In this assignment you will use the MyString class that you wrote earlier in this course.
A palindrome is a string that reads the same forward and backward. Write a program that reads in any number of MyStrings from the user and determines if each MyString is
a palindrome. The user will terminate each MyString by pressing the return (or enter) button. The user will indicate that there are no more MyStrings by entering "quit".
To do this you must write a recursive function named isAPalindrome that takes a single MyString argument and two arguments that are bounds on MyString indices. The
function must examine the part of the argument between the two bounds (including the bounds) and return true if this part of the argument is a palindrome, false if it is not a
palindrome. The function must be recursive and must not call any other functions except ispunct(), isspace(), and toupper() (described below).
Do not make any changes to the MyString class (except, if necessary, to correct errors in your MyString class). In particular, note that the isAPalindrome() function is not part
of the MyString class. Your client file, main.cpp, will contain your main() function and your isAPalindrome() function. Do not use the C++ string class or arrays or vectors or
any other container other than MyString.
Follow this sample output closely:
Enter a string: Able was I, ere I saw Elba
Able was I, ere I saw Elba is a palindrome.
Enter a string: peanut butter
peanut butter is not a palindrome.
Enter a string: quit
In determining whether a string is a palindrome, this function must consider uppercase and lowercase letters to be the same and ignore punctuation characters and
whitespace characters. You must not modify the argument in any way or make a copy of the argument to accomplish this. The simplest way to handle uppercase/lowercase
issues is to make everything uppercase on the fly, right at the instant that you are comparing the two characters.
Full documentation is required.
Hints:
•
You will want to use three functions that are in the cctype library (i.e. you must #include cctype to use them). They are ispunct(char), a bool function which returns true
if its argument is a punctuation mark and false otherwise, isspace(char), which returns true if its argument is a whitespace character and false otherwise, and
toupper(char), which returns the uppercase equivalent of its argument (without changing the argument itself).
• I strongly suggest that you first write this program so that it works in the general case (i.e. assuming that all letters are uppercase and no characters are punctuation
characters or whitespace characters), and then add code to handle the uppercase/lowercase and punctuation/whitespace issues.
•
•
•
Make sure you try a palindrome that starts and ends with the same letter but is not a palindrome. Returning a false positive in this case is one of the most common
errors that students make.
Another common error is calling this value-returning function as if it was a void function. You can't say "isAPalindrome (str1, leftBound, highBound);" on a line by itself.
It doesn't do anything.
Also, make sure that every case in your function has a return statement. Often students submit programs that worked perfectly for them, but they were just getting
lucky, and the computer was returning the correct value by chance when there was no return statement.
• If leftBound > rightBound, that means that the MyString under consideration is the empty string. An empty string reads the same forward and backward, so it is a
palindrome.
Transcribed Image Text:In this assignment you will use the MyString class that you wrote earlier in this course. A palindrome is a string that reads the same forward and backward. Write a program that reads in any number of MyStrings from the user and determines if each MyString is a palindrome. The user will terminate each MyString by pressing the return (or enter) button. The user will indicate that there are no more MyStrings by entering "quit". To do this you must write a recursive function named isAPalindrome that takes a single MyString argument and two arguments that are bounds on MyString indices. The function must examine the part of the argument between the two bounds (including the bounds) and return true if this part of the argument is a palindrome, false if it is not a palindrome. The function must be recursive and must not call any other functions except ispunct(), isspace(), and toupper() (described below). Do not make any changes to the MyString class (except, if necessary, to correct errors in your MyString class). In particular, note that the isAPalindrome() function is not part of the MyString class. Your client file, main.cpp, will contain your main() function and your isAPalindrome() function. Do not use the C++ string class or arrays or vectors or any other container other than MyString. Follow this sample output closely: Enter a string: Able was I, ere I saw Elba Able was I, ere I saw Elba is a palindrome. Enter a string: peanut butter peanut butter is not a palindrome. Enter a string: quit In determining whether a string is a palindrome, this function must consider uppercase and lowercase letters to be the same and ignore punctuation characters and whitespace characters. You must not modify the argument in any way or make a copy of the argument to accomplish this. The simplest way to handle uppercase/lowercase issues is to make everything uppercase on the fly, right at the instant that you are comparing the two characters. Full documentation is required. Hints: • You will want to use three functions that are in the cctype library (i.e. you must #include cctype to use them). They are ispunct(char), a bool function which returns true if its argument is a punctuation mark and false otherwise, isspace(char), which returns true if its argument is a whitespace character and false otherwise, and toupper(char), which returns the uppercase equivalent of its argument (without changing the argument itself). • I strongly suggest that you first write this program so that it works in the general case (i.e. assuming that all letters are uppercase and no characters are punctuation characters or whitespace characters), and then add code to handle the uppercase/lowercase and punctuation/whitespace issues. • • • Make sure you try a palindrome that starts and ends with the same letter but is not a palindrome. Returning a false positive in this case is one of the most common errors that students make. Another common error is calling this value-returning function as if it was a void function. You can't say "isAPalindrome (str1, leftBound, highBound);" on a line by itself. It doesn't do anything. Also, make sure that every case in your function has a return statement. Often students submit programs that worked perfectly for them, but they were just getting lucky, and the computer was returning the correct value by chance when there was no return statement. • If leftBound > rightBound, that means that the MyString under consideration is the empty string. An empty string reads the same forward and backward, so it is a palindrome.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT