I have written some code that will take in a string and print out the
reverse, but I also want it to check for upper and lower case and swap them.
Will someone assist me?
include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <algorithm>
using std::reverse;
int main() {
cout << "Enter a string.\n";
string name;
getline(cin, name);
reverse(name.begin(), name.end());
cout << name << '\n';
} 9 2649
"B Williams" <wi*******@hotmail.comwrote:
I have written some code that will take in a string and print out the
reverse, but I also want it to check for upper and lower case and swap them.
Will someone assist me?
include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <algorithm>
using std::reverse;
int main() {
cout << "Enter a string.\n";
string name;
getline(cin, name);
reverse(name.begin(), name.end());
cout << name << '\n';
}
I'm not quite sure what you mean, could you provide some sample input
and output? For example should: AbCd turn into dCbA or DcBa?
"Daniel T." <da******@earthlink.netwrote in message
news:da****************************@news.west.eart hlink.net...
"B Williams" <wi*******@hotmail.comwrote:
>I have written some code that will take in a string and print out the reverse, but I also want it to check for upper and lower case and swap them. Will someone assist me?
include <iostream> using std::cout; using std::cin; using std::endl;
#include <string> using std::string;
#include <algorithm> using std::reverse;
int main() { cout << "Enter a string.\n"; string name; getline(cin, name); reverse(name.begin(), name.end()); cout << name << '\n';
}
I'm not quite sure what you mean, could you provide some sample input
and output? For example should: AbCd turn into dCbA or DcBa?
If I enter BackDrop, and want the program to produce the output PORdKCAb
In article <Ag*******************@newsfe18.lga>,
"B Williams" <wi*******@hotmail.comwrote:
"Daniel T." <da******@earthlink.netwrote in message
news:da****************************@news.west.eart hlink.net...
"B Williams" <wi*******@hotmail.comwrote:
I have written some code that will take in a string and print out the
reverse, but I also want it to check for upper and lower case and swap
them.
Will someone assist me?
include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <algorithm>
using std::reverse;
int main() {
cout << "Enter a string.\n";
string name;
getline(cin, name);
reverse(name.begin(), name.end());
cout << name << '\n';
}
I'm not quite sure what you mean, could you provide some sample input
and output? For example should: AbCd turn into dCbA or DcBa?
If I enter BackDrop, and want the program to produce the output PORdKCAb
char swapCase( char c )
{
char result = tolower( c );
if ( islower( c ) )
result = toupper( c );
return result;
}
transform( name.begin(), name.end(), name.begin(), &swapCase );
"Daniel T." <da******@earthlink.netwrote in message
news:da****************************@news.west.eart hlink.net...
In article <Ag*******************@newsfe18.lga>,
"B Williams" <wi*******@hotmail.comwrote:
>"Daniel T." <da******@earthlink.netwrote in message news:da****************************@news.west.ear thlink.net...
"B Williams" <wi*******@hotmail.comwrote:
I have written some code that will take in a string and print out the reverse, but I also want it to check for upper and lower case and swap them. Will someone assist me?
include <iostream> using std::cout; using std::cin; using std::endl;
#include <string> using std::string;
#include <algorithm> using std::reverse;
int main() { cout << "Enter a string.\n"; string name; getline(cin, name); reverse(name.begin(), name.end()); cout << name << '\n';
}
I'm not quite sure what you mean, could you provide some sample input
and output? For example should: AbCd turn into dCbA or DcBa?
If I enter BackDrop, and want the program to produce the output PORdKCAb
char swapCase( char c )
{
char result = tolower( c );
if ( islower( c ) )
result = toupper( c );
return result;
}
transform( name.begin(), name.end(), name.begin(), &swapCase );
Daniel,
where would that go in my code?
On Sun, 17 Dec 2006 20:56:22 -0500 in comp.lang.c++, "B Williams"
<wi*******@hotmail.comwrote,
>transform( name.begin(), name.end(), name.begin(), &swapCase );
Daniel, where would that go in my code?
You didn't really write any of it, did you?
"B Williams" <wi*******@hotmail.comwrote:
"Daniel T." <da******@earthlink.netwrote:
>"B Williams" <wi*******@hotmail.comwrote:
>>"Daniel T." <da******@earthlink.netwrote: "B Williams" <wi*******@hotmail.comwrote:
I have written some code that will take in a string and print out the reverse, but I also want it to check for upper and lower case and swap them. Will someone assist me? > include <iostream> using std::cout; using std::cin; using std::endl; > #include <string> using std::string; > #include <algorithm> using std::reverse; > int main() { cout << "Enter a string.\n"; string name; getline(cin, name); reverse(name.begin(), name.end()); cout << name << '\n'; > }
I'm not quite sure what you mean, could you provide some sample input and output? For example should: AbCd turn into dCbA or DcBa?
If I enter BackDrop, and want the program to produce the output PORdKCAb
char swapCase( char c ) { char result = tolower( c ); if ( islower( c ) ) result = toupper( c ); return result; }
transform( name.begin(), name.end(), name.begin(), &swapCase );
where would that go in my code?
I have to leave something for you to do. :-) The swapCase function can
go anywhere outside of the main function (though if you put it after
'main' or in a different cpp file, you will need to declare it.) The
'transform' line needs to go somewhere between the 'getline' and 'cout
<< name'.
BTW, like 'reverse', 'transform' is a standard algorithm. Here is
another way to write swapCase:
char swapCase( char c ) {
return islower( c ) ? toupper( c ) : tolower( c );
}
"David Harmon" <so****@netcom.comwrote in message
news:45****************@news.west.earthlink.net...
On Sun, 17 Dec 2006 20:56:22 -0500 in comp.lang.c++, "B Williams"
<wi*******@hotmail.comwrote,
>>transform( name.begin(), name.end(), name.begin(), &swapCase );
Daniel, where would that go in my code?
You didn't really write any of it, did you?
The reverse function is in the C++ standard library, so I didn't have to
write it, but I did know enough to get the syntax correct.
"Daniel T." <da******@earthlink.netwrote in message
news:da****************************@news.west.eart hlink.net...
"B Williams" <wi*******@hotmail.comwrote:
>"Daniel T." <da******@earthlink.netwrote:
>>"B Williams" <wi*******@hotmail.comwrote: "Daniel T." <da******@earthlink.netwrote: "B Williams" <wi*******@hotmail.comwrote: > >I have written some code that will take in a string and print >out the reverse, but I also want it to check for upper and lower >case and swap them. Will someone assist me? >> >include <iostream> >using std::cout; >using std::cin; >using std::endl; >> >#include <string> >using std::string; >> >#include <algorithm> >using std::reverse; >> >int main() { > cout << "Enter a string.\n"; > string name; > getline(cin, name); > reverse(name.begin(), name.end()); > cout << name << '\n'; >> >} > I'm not quite sure what you mean, could you provide some sample input and output? For example should: AbCd turn into dCbA or DcBa?
If I enter BackDrop, and want the program to produce the output PORdKCAb
char swapCase( char c ) { char result = tolower( c ); if ( islower( c ) ) result = toupper( c ); return result; }
transform( name.begin(), name.end(), name.begin(), &swapCase );
where would that go in my code?
I have to leave something for you to do. :-) The swapCase function can
go anywhere outside of the main function (though if you put it after
'main' or in a different cpp file, you will need to declare it.) The
'transform' line needs to go somewhere between the 'getline' and 'cout
<< name'.
BTW, like 'reverse', 'transform' is a standard algorithm. Here is
another way to write swapCase:
char swapCase( char c ) {
return islower( c ) ? toupper( c ) : tolower( c );
}
Thanks Daniel, I got it to work. I have gotten so much from this NG over the
past year that I was attempting to help someone else. I'm no where the help
person yet.
In article <Mg***********@newsfe18.lga>,
B Williams <wi*******@hotmail.comwrote:
> "Daniel T." <da******@earthlink.netwrote in message news:da****************************@news.west.ear thlink.net...
>"B Williams" <wi*******@hotmail.comwrote:
>>"Daniel T." <da******@earthlink.netwrote: "B Williams" <wi*******@hotmail.comwrote: "Daniel T." <da******@earthlink.netwrote: >"B Williams" <wi*******@hotmail.comwrote: >> >>I have written some code that will take in a string and print >>out the reverse, but I also want it to check for upper and lower >>case and swap them. Will someone assist me? >>> If I enter BackDrop, and want the program to produce the output PORdKCAb
char swapCase( char c ) { char result = tolower( c ); if ( islower( c ) ) result = toupper( c ); return result; }
Just a note to the OP:
Please be aware that the above or even the concept of "tolower" is
mainly only valid for basic US-ASCII in basic English.
If you eventually get a job in the software industry, please do not
ever make such a simplistic assumption. Billions of lines of code
have had to be rewritten because of assumption that the software would
never need to move outside the 7 bits ASCII character set.
If that's a course assignment, add a disclaimer to your submission.
If I were the teacher, I would add bonus points to whoever points this
out.
Yan This discussion thread is closed Replies have been disabled for this discussion. Similar topics
4 posts
views
Thread by programmerforhire |
last post: by
|
3 posts
views
Thread by MHenry |
last post: by
|
6 posts
views
Thread by Ian Gibbons |
last post: by
|
17 posts
views
Thread by Janice |
last post: by
|
19 posts
views
Thread by Eric Lindsay |
last post: by
|
1 post
views
Thread by Rahul |
last post: by
|
2 posts
views
Thread by Franky |
last post: by
|
2 posts
views
Thread by shuisheng |
last post: by
|
10 posts
views
Thread by CuTe_Engineer |
last post: by
| | | | | | | | | | |