Banner
Xtra Smileys
[Open]
We Unite Gaming
May 23, 2025, 12:31:53 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to We Unite Gaming!
Formerly Wii Unite/Wii Unite Gaming
 
  Home Help Search Arcade Gallery Youtube Channel Chatbox Staff List Login Register  

C++

Pages: [1]   Go Down
  Print  
Author Topic: C++  (Read 189 times)
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
C++
« on: November 12, 2012, 11:59:03 pm »

Anyone here who is fluent in this lovely language?
Report Spam   Logged


Share on Bluesky Share on Facebook

Turboweasle
Administrator
WU Guru
*

Karma: 228
Offline Offline

PSN: Turboweasle
Posts: 16556


Turboweasle: everyone's favorite speedy rodent


View Profile
« Reply #1 on: November 13, 2012, 12:00:26 am »

C++ taught me to love and hate pointers.
Report Spam   Logged

"And I also told the students that, for the sake of humanity's future, I hoped they were all sterile." - Ignatius Reilly.
Never mind what your daughter is taught in school; what she remembers is what she has learned from you.
Anti-Noob Fortress of Veteraness Council Member
~Turboweasle~

I NEVER squeeze my jubblies, so that stuff wouldn't work for me.
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
« Reply #2 on: November 13, 2012, 12:15:04 am »

Just learned pointers today.  Amazing things.  Who knew addresses were actually important?

Anyway I have this lab where I have to convert a string into its uppercase version...  I'm just getting the user to input a string of chars into a char array so that I can toupper them individually in another function...

void upperFunct(char array[])
{
                for (int i = 0; ; i++ ) {
         array = toupper(array);
      }
}

Should that not be sufficient?  Doesn't work at all.  I remember my prof talking about some get.line function but I'm not sure how the heck that thing works and if it would help in this situation.

I hate working with char and string data types... They always confuse the hell out of me and are so much more complicated than those nice ints and doubles and floats.
Report Spam   Logged


Turboweasle
Administrator
WU Guru
*

Karma: 228
Offline Offline

PSN: Turboweasle
Posts: 16556


Turboweasle: everyone's favorite speedy rodent


View Profile
« Reply #3 on: November 13, 2012, 12:29:22 am »

Yeah, getline is probably going to be your best friend for a lot of things.  Here's a useful link to it: http://www.cplusplus.com/reference/string/getline/

You'd use it like this: getline (cin,str);.


As for making the first letter capitalized, I'm not really that familiar with the toupper method, but it might be easier to use something like while (cin.get(ch)) where ch is a character variable.  That'll read in until a newline delimiter is read, I think.

From there you can just assign the char at array[0] to an int which will convert it to its Unicode value, then subtract 32 from it to get its uppercase version (going by this chart) and assign that new value back to *a char variable at* array[0].

I've always found it easier to deal with ints when messing with "strings", so that's typically what I go with.

*EDIT: Forgot to mention putting it back in a char variable, otherwise you'd just be assigning an int to the array.
Report Spam   Logged

"And I also told the students that, for the sake of humanity's future, I hoped they were all sterile." - Ignatius Reilly.
Never mind what your daughter is taught in school; what she remembers is what she has learned from you.
Anti-Noob Fortress of Veteraness Council Member
~Turboweasle~

I NEVER squeeze my jubblies, so that stuff wouldn't work for me.
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
« Reply #4 on: November 13, 2012, 12:38:50 am »

Honestly, I've been searching the Internet for a couple of hours for an answer I like, but most of the answers involve what you suggested with the unicode (I think it's called ASCII, actually) thing.  I think it goes something like ch has to between 97 and 122 and then you subtract 'A' from 'a' or something messed up like that.  However, my cutie pie of a prof doesn't really like us using things in our code that we have yet to learn in class.

Honestly, this question is probably the simplest thing in the world, but I can't wrap my head around it.  I'd rather make a code that can print coplex pictures using characters than do this.
Report Spam   Logged


Turboweasle
Administrator
WU Guru
*

Karma: 228
Offline Offline

PSN: Turboweasle
Posts: 16556


Turboweasle: everyone's favorite speedy rodent


View Profile
« Reply #5 on: November 13, 2012, 12:46:18 am »

Yeah, it is ASCII.  That Unicode was my Java Data Structures lecture getting the better of me.

However, my cutie pie of a prof doesn't really like us using things in our code that we have yet to learn in class.

Well that's just darling.  Heavens forbid you do something practical.



The only things I can think of that might make your method not work (assuming it compiles without error?) is that you're not specifying what part of the array to use the toupper method on.  Maybe it goes through the array iteratively regardless (I don't know since I've never used it), but giving it an index might help.  So for your case it would just be array[0].
Report Spam   Logged

"And I also told the students that, for the sake of humanity's future, I hoped they were all sterile." - Ignatius Reilly.
Never mind what your daughter is taught in school; what she remembers is what she has learned from you.
Anti-Noob Fortress of Veteraness Council Member
~Turboweasle~

I NEVER squeeze my jubblies, so that stuff wouldn't work for me.
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
« Reply #6 on: November 13, 2012, 12:56:54 am »

Let me put the question in context...  So one of the very first codes I had to write in that class was a multiple choice quiz that accepts a couple of different answers.  For example, here's the first question of the test:

cout << "What is the name given to the number 1^100, \n(the number 1 followed by 100 zeros)?\nA. Fractal\nB. Googol\nC. Centillion\nD. Googolplex" << endl;
   cout<< "Response: "; cin >> answerOne;
   if ( answerOne == "b" || answerOne == "B" || answerOne == "GOOGOL"  || answerOne == "googol" || answerOne == "Googol" ) {
      cout << "Correct!\n\n";
      total++; }
   else
      cout << "Sorry, the correct response was Googol.\n\n";

Ugliest code, I know.  But we have to revisit this program and change it so that the answers that the user gives can be any combination of lowercase and uppercase and they would still receive a point for it.
Report Spam   Logged


Turboweasle
Administrator
WU Guru
*

Karma: 228
Offline Offline

PSN: Turboweasle
Posts: 16556


Turboweasle: everyone's favorite speedy rodent


View Profile
« Reply #7 on: November 13, 2012, 01:10:48 am »

Right, I see.  So you do want to convert the entire input to uppercase, yes?

If that's the case I'd have two arrays, one with only one cell and the other with six.  I'd read in the input and keep track of a count to tell how long it is, and if it was one I'd stick the input into the first array and if it was six I'd stick it into the second array.  From there you can have a for loop for each array (you'd only use one, though).  Your i variable in the loop would also act as your array index, at which point you can call the toupper method on one array index at a time.  Then have a string and append the chars to the string, with something like str += char;.

Then compare that to your if statement and output whatever the case is.



I think that will work, but it's 1:11 AM and I'm sleep deprived so I'm not promising anything.  I'll get back to you in the morning if I think of anything else.
Report Spam   Logged

"And I also told the students that, for the sake of humanity's future, I hoped they were all sterile." - Ignatius Reilly.
Never mind what your daughter is taught in school; what she remembers is what she has learned from you.
Anti-Noob Fortress of Veteraness Council Member
~Turboweasle~

I NEVER squeeze my jubblies, so that stuff wouldn't work for me.
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
« Reply #8 on: November 13, 2012, 08:43:20 am »

Naaaah haven't learned objects like those, yet.  Would be easier, though.
Report Spam   Logged


RON
RON
WU Elite
*

Karma: 43
Offline Offline

Posts: 430


View Profile
« Reply #9 on: November 13, 2012, 01:26:34 pm »

Shoot -I forgot ya all are smart, I thought this topic was about a new bra size.
Report Spam   Logged
Ress
WU Guru
******

Karma: 47
Offline Offline

Posts: 15283



View Profile
« Reply #10 on: November 13, 2012, 03:22:28 pm »

The answer was so damn easy...  You were right zyr with using str.length() object.  We did sort of learn that but I never really do pay attention in that class.
Report Spam   Logged


wtZzz
WU Elite
**

Karma: 16
Offline Offline

Posts: 439


View Profile
« Reply #11 on: November 18, 2012, 01:46:39 pm »

Noobs
Report Spam   Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
© 2008-2014 We Unite Gaming, Wii Unite Gaming, Wii Unite
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy