Question: this is a program that checks to see if a sentence can be a palindrome or not. ( Palindrome happens when a word or a
this is a program that checks to see if a sentence can be a palindrome or not. ( Palindrome happens when a word or a sentence is the same when you read it from left to right or right to left). This is the code that I have so far and it works fine. it removes the symbols and number and convert all letters to capital letter. I need help implementing it into a while loop so user can enter as many sentences they want and the press q to quit!
//Rojin Shahbazian
//CECS282
//Assignment #5
#include
#include
using namespace std;
void transform( char *raw, char *testStr);
bool testPalindrome(char *str);
int main()
{
char str[80]; //declaration of array
char convertedStr[80];
cout<<"Enter a string, press 0 to exit"< //while(string //cout<<"Enter String: "; gets(str); //get the string from the user transform( str, convertedStr); //to check the status of palindrome bool res = testPalindrome(convertedStr); if(res){ cout<<" Entered String is Palindrome"; } else{ cout<<" Entered String is not a Palindrome"; } return 0; } void transform(char *raw, char *testStr){ int i = 0; int j = 0; while(*(raw+i)) { if(isalpha(*(raw+i))) { *(raw+i) = toupper(*(raw+i)); *(testStr+j) = *(raw+i); j++; } i++; } /* int strlength = strlen(raw); int front = 0; for(int i = 0; i < strlength; i++) { raw[i] = toupper(raw[i]); // will be used to convert to upper case } for(int i = 0; i < strlength; i++) { if(isalpha(raw[i])){ testStr[front] = raw[i]; front++; }*/ *(testStr+j) = NULL; } //function to check palindrome bool testPalindrome(char *str){ bool result = true; int strlength = strlen(str); int front = 0,rear = strlength-1; for(int i=0; i< strlength/2;i++){ if(str[front]!=str[rear]){ result = false; break; } } return result; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
