Sign in to follow this  

Quick questions.

This topic is 3722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay I'm reading C++ Program Design: An Introduction to Programming and Object-Oriented Design. Theres this question I'm really stuck on, well not stuck but can't find the answer to from rereading the small section. It asks me: Name the two numeric components of a floating-point number. I was thinking long and double is that what they are asking for? I also got a question about char bytes. It says char bytes are 7 bytes. So is this string 64 or 72 bytes in total: Ben Rush Thanks for your help.

Share this post


Link to post
Share on other sites
Quote:
Original post by scheols
Okay I'm reading C++ Program Design: An Introduction to Programming and Object-Oriented Design. Theres this question I'm really stuck on, well not stuck but can't find the answer to from rereading the small section. It asks me:

Name the two numeric components of a floating-point number.

I was thinking long and double is that what they are asking for?

I also got a question about char bytes. It says char bytes are 7 bytes. So is this string 64 or 72 bytes in total:

Ben Rush

Thanks for your help.


Short answer:
The parts are the significand and the exponent.

long answer:
http://en.wikipedia.org/wiki/Floating_point

Share this post


Link to post
Share on other sites
Quote:
Original post by scheols
Okay I'm reading C++ Program Design: An Introduction to Programming and Object-Oriented Design. Theres this question I'm really stuck on, well not stuck but can't find the answer to from rereading the small section. It asks me:

Name the two numeric components of a floating-point number.

I was thinking long and double is that what they are asking for?


That doesn't make any sense at all as an answer.

Hint: What does component mean? What does numeric mean? A numeric component, then, is a component (of the floating-point number) which itself is numeric.

Quote:
I also got a question about char bytes. It says char bytes are 7 bytes.


What? I can't even guess what you even think a "char byte" is. Please post the exact text you are referring to.

Share this post


Link to post
Share on other sites


They are probably refering to the mantissa and the exponent.
Look them up to see what parts of a floating point number they are and how they work.



The '7 bytes' stuff probably is meant to be 7 'bits'.

CHARs represent ASCII values which are 0..127 (2^7). So thats where the 7 comes from. A string/array of chars was meant to contain text (the 8th bit on each byte is basicly wasted.)

You can use CHAR types for math and use 'unsigned char' to represent a BYTE value 0..255 and the'signed char' can contain values of -128 .. 127. (is usually a good idea to be explicity about siigned/unsigned so there is no complications deciding whiuch way the CHAR type goes by default.


Share this post


Link to post
Share on other sites
I think I read it wrong.

1 Character is 1 byte right?

So: Ben Rush

is equal to 9 bytes since the null character is also a byte.

Quoting from this book:

"Each character takes up 1 byte of storage..... '' is a string constant with zero characters and is often called a null string or empty string...that to has a null character at the end, so it takes up 1 byte of memory."

Share this post


Link to post
Share on other sites
Quote:
Original post by scheols
1 Character is 1 byte right?

Yes, but the size of that byte may vary.

Quote:
So: Ben Rush

is equal to 9 bytes since the null character is also a byte.

In ASCII, yes. In almost any Unicode code page, no. You don't necessarily have to worry about the details of Unicode code pages yet, but you do have to be aware that the things that book is teaching you are not absolute truths.

Share this post


Link to post
Share on other sites

This topic is 3722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this