473,581 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.be gin(), name.end());
cout << name << '\n';

}
Dec 17 '06 #1
9 2780
"B Williams" <wi*******@hotm ail.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.be gin(), 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******@earth link.netwrote in message
news:da******** *************** *****@news.west .earthlink.net. ..
"B Williams" <wi*******@hotm ail.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.be gin(), 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************ *******@newsfe1 8.lga>,
"B Williams" <wi*******@hotm ail.comwrote:
"Daniel T." <da******@earth link.netwrote in message
news:da******** *************** *****@news.west .earthlink.net. ..
"B Williams" <wi*******@hotm ail.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.be gin(), 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******@earth link.netwrote in message
news:da******** *************** *****@news.west .earthlink.net. ..
In article <Ag************ *******@newsfe1 8.lga>,
"B Williams" <wi*******@hotm ail.comwrote:
>"Daniel T." <da******@earth link.netwrote in message
news:da******* *************** ******@news.wes t.earthlink.net ...
"B Williams" <wi*******@hotm ail.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.be gin(), 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*******@hotm ail.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*******@hotm ail.comwrote:
"Daniel T." <da******@earth link.netwrote:
>"B Williams" <wi*******@hotm ail.comwrote:
>>"Daniel T." <da******@earth link.netwrote:
"B Williams" <wi*******@hotm ail.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.be gin(), 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.w est.earthlink.n et...
On Sun, 17 Dec 2006 20:56:22 -0500 in comp.lang.c++, "B Williams"
<wi*******@hotm ail.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******@earth link.netwrote in message
news:da******** *************** *****@news.west .earthlink.net. ..
"B Williams" <wi*******@hotm ail.comwrote:
>"Daniel T." <da******@earth link.netwrote:
>>"B Williams" <wi*******@hotm ail.comwrote:
"Daniel T." <da******@earth link.netwrote:
"B Williams" <wi*******@hotm ail.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.be gin(), 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*******@hotm ail.comwrote:
>
"Daniel T." <da******@earth link.netwrote in message
news:da******* *************** ******@news.wes t.earthlink.net ...
>"B Williams" <wi*******@hotm ail.comwrote:
>>"Daniel T." <da******@earth link.netwrote:
"B Williams" <wi*******@hotm ail.comwrote:
"Daniel T." <da******@earth link.netwrote:
>"B Williams" <wi*******@hotm ail.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
13056
by: programmerforhire | last post by:
Hello all, Is there a way to setup an ms-access table so that when I enter text in the 'datasheet' mode, it will automatically be converted tp upper case. Or must I use a Form for this? rex
3
1697
by: MHenry | last post by:
All the lower case "c" in my database table are now upper case "C" starting in January 2004. All prior data is fine. I just noticed this after installing a Microsoft update patch a couple of days ago. Any ideas what happened, or how to fix? I thought I could change every letter C to lower case, and then change every c that starts a word...
6
2611
by: Ian Gibbons | last post by:
Firstly what type is %x as I've not encountered it before? Now the problem: I'm trying to alter a host masking system for ircd so that it masks all but the isp name and location (if .uk.us etc..). However the crc32 stuff doesnt return as a string, and because the number of hostname fields is not static I need to build a string which contains...
17
11210
by: Janice | last post by:
char* line = "abcd"; How to convert the line to upper case and print? Any option for printf to do this? Thanx
19
26432
by: Eric Lindsay | last post by:
Should HTML 4.01 Strict markup be done in upper case or in lower case? I understand that HTML allows either upper or lower case. I also notice that XHTML apparently requires lower case. However I saw some mention that the HTML DOM uses upper case for markup elements. So, should I worry about what this means? I am inclined to go with...
1
3699
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
2
1935
by: Franky | last post by:
This should be easy to find but I've been looking and looking at the doc and can't find it. Maybe it can't be done. In the IDE editors find/replace I want to use regular expression to change the first letter after "Dim " to lower case. e.g Dim Tmp to Dim tmp can you show me the replace string.
2
1922
by: shuisheng | last post by:
Dear All, Assume I have a class for a cuboid domain. The domain is defined by the cuboid's lower corner, such as (0, 0, 0), and upper corner, such as (1, 1, 1). The upper corner should be always higher than the lower corner. I write a code as below class Domain { private:
10
2096
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes #these are the operations + = , - = , * = , 1/ = only if 0 not in .
0
7788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8299
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8163
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5355
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3799
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1397
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.