Question

Write a program that uses a recursive function to determine whether a string is a character-unit...

Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive.

Background

Palindromes are character sequences that read the same forward or backward (e.g. the strings "mom" or "123 454 321"). Punctuation and spaces are frequently ignored so that phrases like "Dog, as a devil deified, lived as a god." are palindromes. Conversely, even if spaces are not ignored phrases like "Rats live on no evil star" are still palindromes.

Requirements

Command Line Parameters

The program name will be followed by a list of strings. The program will determine whether each string is a palindrome and output the results. Punctuation will always be ignored. An optional flag can preceed a term that modifies how the palindrome is determined.

Strings

Each string will be separated by a space on the command line. If you want to include a string that has spaces in it (e.g. "Rats live on no evil star"), then put quotes around it. The quote characters will not be part of the string that is read in.

Flags

Optional for the user

Must immediately precede the word it applies to.

Must start with a minus (-) sign followed by one or two flag values that can be capital or lower case. e.g. -c, -S, -Cs, -Sc, etc.

There are no spaces between starting minus (-) sign and flag(s).

Flags values are case insensitive.

c or C: Indicates that comparisons should be case-sensitive for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore case-sensitivity. So, for example:

palindrome Mom should evalate as being a palindrome.

palindrome -c Mom should not evalate as being a palindrome.

s or S: Indicates that comparisons should not ignore spaces for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore spaces. So, for example:

palindrome "A nut for a jar of tuna" should evalate as being a palindrome.

palindrome -s "A nut for a jar of tuna" should not evalate as being a palindrome.

Options can appear in different flags, e.g. you can use -Sc or -S -c

The same flag cannot appear more than one time prior to a term. If it does, print a usage statement and exit program.

Code Expectations

Program should only get user input from the command line. (i.e. "cin" should not be anywhere in your code).

Required Functions:printUsageInfo - Print program usage message in case no input strings were found at command line.

Parameter(s): a string representing the name of the executable from the command line.

Return: void.

isPalindrome - This function determines whether a string is a character-unit palindrome.

Parameter(s): an input string, and two boolean flags that say whether to consider case-sensitivity and whether to not ignore spaces.

Return: bool.

All functions should be placed in a separate file following the conventions we covered.

Program Flow

Your program will take arguments from the command-line.

Determine if you have enough arguments. If not, output a usage message and exit program.

Loop through all arguments:Determine if a flag or a term.If flag

Process and set values to use when processing a palindrome.

If flag set too many times, e.g. -s -S or -scs, print usage message and exit program immediately.

If term:

Process by calling isPalindrome function with flag values.

Output results

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Write a program that uses a recursive function to determine whether a string is a character-unit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

  • Write a recursive function, take a String as input, return true, if the String is a...

    Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...

  • 1.) Write a recursive function named isPalindrome that will take a single string as an argument...

    1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and...

    C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are: "radar" "able was i ere i saw elba" and, if you ignore blanks: "a man a plan a canal panama" Write a recursive function testPalindrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Use the function in a complete program...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Write a C++ program to check whether a string is a palindrome. Input a string (word)...

    Write a C++ program to check whether a string is a palindrome. Input a string (word) from the keyboard. Assume the letters are case-insenstive. Use the C++ string class. Refer to the sample output below. Sample Runs: Enter a string: otto; otto is a palindrome Enter a string: A A is a palindrome Enter a string: heooh heooh is not a palindrome

  • OK, here is the project, I need to get started and just don't understand how to...

    OK, here is the project, I need to get started and just don't understand how to get the registers, the array, stack to work with the UART. Just looking for some help to start, not looking for you to solve the project. I have to write a program that receives a string of characters via the UART, checks if this string is a palindrome, and then uses a print function to print either "Yes" or "No". A palindrome sequence of...

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT