472,145 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

help with upper and lower case conversion

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';

}
Dec 17 '06 #1
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?
Dec 18 '06 #2

"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
Dec 18 '06 #3
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 );
Dec 18 '06 #4

"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?
Dec 18 '06 #5
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?

Dec 18 '06 #6
"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 );
}
Dec 18 '06 #7

"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.
Dec 18 '06 #8

"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.
Dec 18 '06 #9
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

Dec 19 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by programmerforhire | 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 shuisheng | last post: by
10 posts views Thread by CuTe_Engineer | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.