Question: C++ Please Modify your program to read candidate palindromes from the file palindromes.txt, one per line, and answer questions about the contents of that file.
C++ Please
Modify your program to read candidate palindromes from the file palindromes.txt, one per line, and answer questions about the contents of that file.
Ignore any leading or trailing spaces; only spaces within the string are considered.
All answers on chegg are incorrect, so please do not copy and paste them.
palindromes.txt file:
racecar racecar!!! Race car TACO CAT Able was I, ere I saw Elba.... A man, a plan, a canal - Panama!!! King, are you glad you are king? Al lets Della call Ed "Stella." Was it a car or a cat I saw? Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned. afd8792h34af7980897fa43h2978dfa afd879 2h34af798 0897fa4 3h2 978dfa afd8792h34af79380897fa43h2978dfa sleep faced time sap gayy new evil live wen yag pas emit decaf peels sleep ogre stoops secret stink state amore real room know man nam wonk moor laer roma etats knits terces spoots ergo peels Devil time spins real fool secret trap part terces loof laer snips emit lived looks sense, animal liar bibrank some emos knar bib rail lamina esnes skool! stink rats state sense sleep know reined animal time Devil lived emit terces lamina denier wonk peels esnes etats star knits animal spins real edit man trap spinx secret terces nips part nam tide laer snips lamina snow looks leat sleep deep edit state Devil recal slit rats startils lacer lived etats tide peed peels tael skool wons fool animal edit time sense trap saw word drow was part esnes emit tide lamina loof secret poor edit sense keep sleep fool big real deep peed laer gib loof peels peek esnes tide roop terces How are you going to do on this quiz ????? ziuq siht no od ot gniog uoy era woH STRICT_ TCIRTS xxx12321xxx
Program that needs to be modified:
#include
using namespace std;
bool isNumeric(string s) { for (int i = 0; i < s.length(); i++) if (isdigit(s[i]) == false) return false;
return true; }
//function for recursive method bool Palindrome(string& str, int low, int up) { if (low >= up) return true; if (str[low] != str[up]) return false; return Palindrome(str, ++low, --up); }
//function to convert into uppercase string convertUpper(string str) { int i; for (i = 0; i < str.length(); i++) if (str[i] >= 'a' && str[i] <= 'z') str[i] = str[i] - 32; return str; } //function to remove the punctuations string RemovePunctuation(string str) { int i; string s; for (i = 0; i < str.length(); i++) if (str[i] >= 'A' && str[i] <= 'Z' || str[i] == ' ') s = s + str[i]; return s; } //function to remove the spaces string RemoveSpace(string str) { int i; string s; for (i = 0; i < str.length(); i++) if (str[i] != ' ') s = s + str[i]; return s; }
int main() { string str, s; bool first, second, num; cout << endl << "Enter a string: "; getline(cin, str);
if (isNumeric(str)) { if (Palindrome(str, 0, str.length() - 1)) cout << endl << "It is a decimal palindromic number"; else cout << endl << "Not palindrome"; } else { cout << endl << "Entered string is : " << str; s = convertUpper(str); s = RemovePunctuation(s);
//function to check for palindrome first = Palindrome(s, 0, s.length() - 1); s = RemoveSpace(s); //function to check for palindrome second = Palindrome(s, 0, s.length() - 1);
if (first) cout << endl << "The string is Strict Palindrome"; else if (second) cout << endl << "The string is Regular Palindrome"; else cout << endl << "The string is Not Palindrome"; } }
Answer this questions:
How many strings in the file are not palindromes?
How many strings in the file are strict palindromes?
How many strings in the file are ordinary, but not strict, palindromes?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
