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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education