正在加载图片...
Part B:This part you need to do on computer. 1.Palindrome Checker (30)A palindrome is a word or phrase which is exactly the same if the letters in the word or phrase are reversed-for example the words pup, civic,radar,and racecar are all palindromes.For this problem you will write a program which checks whether a word or phrase entered is a palindrome.If the data entered is a palindrome,print"XXX is a palindrome!",otherwise print "XXX is Not a palindrome."Your checker should work for phrases as well as words,and should ignore spaces,punctuation,and upper/lower-case differences.Thus the phrase:"A man,a plan,a canal,Panama!"should be correctly identified as a palindrome. The program only tests a single word and then stops execution.If you want to check another word or phrase,you'll have to run the program again.Here is a screenshot showing the program in action: #include<Vg101class.h> #include <string> #include <cctype> using namespace std; string preProcess(string str) string newString; for (int i=0,j=0;i<str.length ()i++) if (isalpha (str[i])) newString.append (1,tolower (str[i])); return newString; } bool IsPalindrome (string str) str preProcess (str); int i=0,j=str.length ()-1; bool equal true; while (equal &&i<j) equal str[i++]=str[j--]; return equal; } int main (int argc,char *argv[]) ConsoleT console; string str argc ==2 argv[1]:"A man,a plan,a canal,Panama!"; console.printLine (str,is "IsPalindrome (str)?"""NOT",a palindrome.\n"); return 0;Part B: This part you need to do on computer. 1. Palindrome Checker (30) A palindrome is a word or phrase which is exactly the same if the letters in the word or phrase are reversed—for example the words pup, civic, radar, and racecar are all palindromes. For this problem you will write a program which checks whether a word or phrase entered is a palindrome. If the data entered is a palindrome, print “XXX is a palindrome!”, otherwise print “XXX is Not a palindrome.” Your checker should work for phrases as well as words, and should ignore spaces, punctuation, and upper/lower-case differences. Thus the phrase: “A man, a plan, a canal, Panama!” should be correctly identified as a palindrome. The program only tests a single word and then stops execution. If you want to check another word or phrase, you’ll have to run the program again. Here is a screenshot showing the program in action: #include<Vg101class.h> #include <string> #include <cctype> using namespace std; int main (int argc, char *argv[]) { ConsoleT console; string str = argc == 2 ? argv[1] : "A man, a plan, a canal, Panama!"; console.printLine (str, " is ", IsPalindrome (str) ? "" : "NOT", " a palindrome.\n"); return 0; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有