Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: help with C++ code  (Read 7930 times)

0 Members and 1 Guest are viewing this topic.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: help with C++ code
« Reply #15 on: April 22, 2010, 06:38:46 PM »
The advantage of 2x3i5x's version is it is actually C++, not C pasted into C++.  :P
I was trying to dereference Null Pointers before it was cool.

EEVIAC

  • Guest
Re: help with C++ code
« Reply #16 on: April 22, 2010, 07:50:57 PM »
Thanks, 2x3i5x   ;)

EEVIAC

  • Guest
Re: help with C++ code
« Reply #17 on: April 23, 2010, 02:16:52 AM »
@ 2x3i5x


Just for the record, when you declare "grade" as a char type, does that mean entering "A" is really the ascii equivalent "65", and is incremented to "66" (B), when grade = grade + 1 ?     Is that how this is working ?


From what I understand, it's the cin object that converts character constants such as A to it's equivalent numeric value which is stored into ram, and when outputted, it's the cout object converts that numeric constant in ram back to the ascii equivalent..  hehe   I think I got this..  :P






BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: help with C++ code
« Reply #18 on: April 23, 2010, 02:27:20 AM »
EEVIAC: that's how it works with strings in every language, though- the characters are of course stored as their ASCII/ANSI/Unicode equivalent. The difference here is that C and C++ have no "byte" datatype- their "byte" is the char data type.

the i/o routines, and everything, treat it as a number. Nothing treats it like a string, or a string character.- however, when C or C++ send it to the Operating System display routines- the console treats it like an ASCII code- a byte being sent with 65 is represented with an A. this makes sense, in that printing 65 instead would indicate the writing of two, rather then one, byte. So we have it like this:

1. C/C++ program works with char data type (perhaps an array). it is treated, they get no special treatment- uppercasing is as easy as subtracting 32 in certain circumstances, and lowercase by adding 32.

2. at some point, the program sends the char data off to an output function.

3. the output function is explicitly designed to accept an array of bytes and translate them into display characters. note that this obviously doesn't apply for writing to a file- in that case the data is simply written to the file (if the file is later loaded by a text editor the various byte values are translated to the characters you see on-screen).
I was trying to dereference Null Pointers before it was cool.

EEVIAC

  • Guest
Re: help with C++ code
« Reply #19 on: April 23, 2010, 02:34:55 AM »
ahh, illumination    8)



you get another Lolipop, BC

EEVIAC

  • Guest
Re: help with C++ code
« Reply #20 on: April 23, 2010, 03:30:16 AM »
It's interesting that there are so many ways to accomplish a single task in programming.

The assignment that I was trying to do here wanted an output as specified in my previous posts.   I had to go back through the chapter to try to guess which way the author intended the program to be written.  I assumed the assignment was to be written using techniques discussed in it's corresponding chapter.  It didn't occur to me that I could have done it the way 2x3i5x suggested..  With out the instructor to go along with the book it's kind of difficult to figure out what's required.  In other words, I hope I learned what the author intended... 

What's really hard is trying to comprehend EVERYTHING that is discussed in the chapters, and recalling that information when you actually need it at the end of the chapter... For me, by the time I get through a chapter, sometimes I can't recall what was said at the beginning of the chapter...  :(          I wish I had photographic memory.  Programming is probably much easier certain people..

2x3i5x



    Expert
  • Thanked: 134
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 10
Re: help with C++ code
« Reply #21 on: April 23, 2010, 01:37:35 PM »
Yeah, there are different ways to do same thing. Some are more efficient methods than others and some are simpler to write out. So it takes practice to get things in place.  :P