All pastes #8915 Raw Edit

Miscellany

public cpp v1 · immutable
#8915 ·published 2005-04-06 08:46 UTC
rendered paste body
#include <iostream>#include <string>#include <cctype>using namespace std;void swap(char&	v1, char& v2);//switches values of v1 and v2string reverse(const string& s);//returns string s in reverse orderstring remove_punct(const string& s, const string& punct);//returns string s with punctuation removedstring make_lower(const string& s);//returns copy of string s with all of the characters lowercasebool is_pal(const string& s);//returns true of s is a palindrome, otherwise returns falseint main(){    char runagain;    do{        string str;        cout << "Enter a candidate for palindrome testing: ";        getline(cin, str);        if(is_pal(str))            cout << "\"" << str + "\" is a palindrome.";        else            cout << "\"" << str + "\" is not a palindrome.";        cout << endl;        cout << "Run the program again? (y/n): ";        cin >> runagain;        cin.ignore();        cout << endl;    } while((runagain == 'y') || (runagain == 'Y'));    return 0;}//end mainvoid swap(char& v1, char& v2){    char temp = v1;    v1 = v2;    v2 = temp;}//end swapstring reverse(const string& s){    int start = 0;    int end = s.length();    string temp(s);    while(start < end)    {        end--;        swap(temp[start], temp[end]);        start++;    }    return temp;}//end reverse//uses functions make_lower, remove_punctbool is_pal(const string& s){    string::const_iterator sForward = s.begin();    string::const_reverse_iterator sBackward = s.rbegin();    bool palindrome = true;    for(; sForward < s.end(), sBackward < s.rend();)    {        if(!isalpha(*sForward)) {            sForward++;            continue;        }        if(!isalpha(*sBackward)) {            sBackward++;            continue;        }        if(tolower(*sForward) != tolower(*sBackward))            palindrome = false;        sBackward++;        sForward++;    }    return palindrome;}