new to c++ __coverting uppercase to lowercase vice versa

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 6
Reputation: d1s_0n3_guy is an unknown quantity at this point 
Solved Threads: 0
d1s_0n3_guy d1s_0n3_guy is offline Offline
Newbie Poster

new to c++ __coverting uppercase to lowercase vice versa

 
0
  #1
Nov 13th, 2008
Write a program that will prompt the user to type in a series of characters. Input these characters into a c-string (char array). For each character, if it is a letter, toggle the case (upper to lower case, or lower to upper case). All other characters leave as is. Print out the string before and after.

and

I i've been use:

#include <cctype>

and

islower(), isupper(), tolower(), and toupper(), and maybe isalpha(). to the help the coding.



In the for loop, use this format:
for (i=0; arrayname[i]; i++)

any suggestion?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #2
Nov 13th, 2008
What have you done so far? We don't solve homeworks
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #3
Nov 13th, 2008
Yes, you've collected all the tools you'll need. Now put them together in some actual code.

I kind of like your for loop - clever way you end it. Goes against my feeling that for loops should be controlled by the value of the counter, but it's more succinct than the equivalent while loop implementation.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,833
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #4
Nov 13th, 2008
Originally Posted by vmanes View Post
I kind of like your for loop - clever way you end it.
As do I. Which automatically makes me believe that it's part of the assignment given by the teacher
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: d1s_0n3_guy is an unknown quantity at this point 
Solved Threads: 0
d1s_0n3_guy d1s_0n3_guy is offline Offline
Newbie Poster

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #5
Nov 14th, 2008
Originally Posted by niek_e View Post
As do I. Which automatically makes me believe that it's part of the assignment given by the teacher

okay i think i got it all together ..check this out..
and it is an assignment.... i was just asking for any input on it...
but here is my code and for the next guy who wants to use it .. i don't mind... in the end its all up to you weather you learn it or not...you might learn something new from it... do what ever you want with it.....


#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

int main ()
{
char letters[20];
char temp;
int i;
cout << "Pease enter characters " << endl;
cin >> letters;
for (i=0; letters[i]; i++)
{
if (isalpha(letters[i]))

{if (islower(letters[i]))
temp=toupper(letters[i]);
if (isupper(letters[i]))
temp=tolower(letters[i]);
cout << temp;
}
else
{temp=letters[i];
cout << temp;
}
}
cout << endl;
cin >> i;

return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: d1s_0n3_guy is an unknown quantity at this point 
Solved Threads: 0
d1s_0n3_guy d1s_0n3_guy is offline Offline
Newbie Poster

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #6
Nov 14th, 2008
and how could i make it better? fancier or what ever.. i like to get a good grasp on this...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 949
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #7
Nov 14th, 2008
Here's code from something I was doing the other-night:
  1. string str = "I'm a fairy! abc xyz ABC XYZ";
  2. int casechanged = 0;
  3.  
  4. cout << str;
  5. for(i = 0; i < str.length(); i++)
  6. {
  7. if(isUpper(str[i])) { str[i] = toLower(str[i]); casechanged = 1; }
  8. if(isLower(str[i]) && casechanged != 1) { str[i] = toUpper(str[i]);}
  9.  
  10. casechanged = 0;
  11. }
  12. cout << str;
  13.  
  14. for(i = 0; i < str.length(); i++)
  15. {
  16. if(isLower(str[i])) { str[i] = toUpper(str[i]); casechanged = 1; }
  17. if(isUpper(str[i]) && casechanged != 1) { str[i] = toLower(str[i]); }
  18.  
  19. casechanged = 0;
  20. }
  21. cout << str;
The isLower/Upper(), and toUpper/toLower(), are my own functions I wrote, just replace them with the proper names of the ones you're using.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: d1s_0n3_guy is an unknown quantity at this point 
Solved Threads: 0
d1s_0n3_guy d1s_0n3_guy is offline Offline
Newbie Poster

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #8
Nov 14th, 2008
koool thanx
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #9
Nov 14th, 2008
Here's your code, cleaned up and simplified a bit.

When posting code here, please use the tags
[code]
your code here
[/code]
This will better preserve your indenting, making the code easier to read.

You should adopt a consistent style of indenting, and use of curly braces. You're mixing styles, which hinders readability. Also use some blank spaces in a line between operators and operands. You're not charged by the byte.
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. char letters[20];
  9. int i;
  10.  
  11. cout << "Pease enter characters " << endl;
  12. cin >> letters;
  13.  
  14. cout << letters << endl; //assignment said display the original
  15.  
  16. for ( i = 0; letters[i]; i++ )
  17. {
  18. if ( isalpha(letters[i] ) )
  19. {
  20. if ( islower(letters[i] ) )
  21. letters[i] = (char) toupper( letters[i] );
  22. else //we know it's a letter, and not lowercase
  23. letters[i] = (char) tolower( letters[i] );
  24. }
  25. //don't do anything to non-alpha
  26. }
  27.  
  28. //display the whole string, not one char at a time in the loop
  29. cout << letters << endl; //the changed version
  30.  
  31. cout << endl;
  32.  
  33. return 0;
  34. }
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: d1s_0n3_guy is an unknown quantity at this point 
Solved Threads: 0
d1s_0n3_guy d1s_0n3_guy is offline Offline
Newbie Poster

Re: new to c++ __coverting uppercase to lowercase vice versa

 
0
  #10
Nov 14th, 2008
thank you ..it does look a lot better ....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC