String Palindrome C++
#include<iostream>
#include<string>
using namespace std;
class StrRev {
public:
string rev(string word) {
int len = word.size();
int start = 0, end = len - 1;
while(start < end) {
char temp = word[start];
word[start] = word[end];
word[end] = temp;
start++;
end--;
}
return word;
cout<<"\nreversed string: "<<word<<endl;
}
};
class palindrome {
public:
void CheckPalindrome(string word, string ReversedWord) {
if(word == ReversedWord) {
cout<<"Palindrome\n";
}
else {
cout<<"Not Palindrome\n";
}
}
};
int main() {
string word;
cout<<"String Palindrome\n";
while(1) {
cout<<"enter a string: ";
cin>>word;
cout<<"\nbefore rev: "<<word<<endl;
StrRev r;
string ReversedWord = r.rev(word);
palindrome p;
p.CheckPalindrome(word, ReversedWord);
}
}
Comments
Post a Comment