There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
quick C++ easy question !!!


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
TypeSK's Avatar
Senior Member with 679 posts.
 
Join Date: Mar 2002
Experience: Intermediate
04-Mar-2003, 09:48 PM #1
quick C++ easy question !!!
ok, i have a small program (i am only in my 2nd class of C++, but this is typically a intro C++ question ...)

this is also due tonight at midnight..so if anyone can help, that would be great ...

i forgot how the bool operator works ...

i am in C++ class, and am doing a class (object oriented programming?)

and in the class, i have functions ..

well, one of the functions go like this:

Code:
  void sequence::advance()
  {
    assert(is_item() == 'true');

    if (current_index == (used - 1))
      current_index = current_index;
    else
      current_index++;
  }
ok, the is_item() function call is a call to another boolean function (i still have to write this function) IGNORE THAT I HAVE "assert(is_item() == 'true');" (w/o quotes) right now, as i just put that there so i know to go back and change it to the right code, which is why im here asking ..

i know i can write this for the boolean function:

Code:
bool sequence::is_item() const
{
if (num2 == 10)
 return true;
else if (num2 != 10)
return false;
}
(remember, this is all in a class...but ignore that as the question doesnt really deal with that)

1. how does the bool work? when it says itll return true or false, is it going to return the char/string "true" or "false" or will it return 0 or 1 (i think 0 is false, 1 is true?) ?

2. based on what the bool function returns (in the function, as ive seen it written elsewhere to "return true" as in the is_item function), is this how i write the code: "assert(is_item() == 'true');" (w/o quotes) ?? or am i to write it another way?

if this sounds confusing, please reply and ill get back to you !! or ill be on AIM ...jaesunSK

thanks !!
__________________
AMD Athlon64 X2 4400+
DFI LanParty nF4 SLI-DR
256MB BFG 7800GTX OC
1GB OCZ Gold 2x512 DC PC3200

It's Not That We Don't Know, It's That We Don't Do What We Do Know
TypeSK's Avatar
Senior Member with 679 posts.
 
Join Date: Mar 2002
Experience: Intermediate
04-Mar-2003, 11:40 PM #2
ttt...

help anyone?
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
05-Mar-2003, 02:08 AM #3
Bools are basically integers, so "false" evaluates to 0 (binary zero, not ASCII zero) and true evaluates to non-zero (note the distinction: non-zero includes all values other than zero, not just, for example, binary 1). Often, true and false are #defined (e.g., #define FALSE 0). You should be making numeric comparisons, not string comparisons.

BTW: your is_item method could be made more efficient. Once you've checked for (num2 == 10), you can just use an else statement to capture all the other possibilities; there's no need to check that (num2 != 10) because that's the only possibility if execution has reached this line.

Hope this helps.
__________________
The slowest component still sits at the keyboard.
TypeSK's Avatar
Senior Member with 679 posts.
 
Join Date: Mar 2002
Experience: Intermediate
05-Mar-2003, 02:32 AM #4
yea...i know...actually, i just threw something in there ... i think i did it right...here is the whole class function calls:

Code:
  void sequence::advance()
  {
    assert(is_item());

    while(is_item())
      {
        current_index++;
        break;
      }
  }

  bool sequence::is_item() const
  {
    if (current_index < used && current_index >= 0)
      return true;
    else
      return false;
  }
well, nevermind...i only put that function calls in....dont think youd care for what the rest of the code does ....

so i had it do the assert, and its right syntax, as it compiled ok, and worked ... and then i did a while the function is true to do the rest also ....

i just finished as you replied ... thanks though !!
__________________
AMD Athlon64 X2 4400+
DFI LanParty nF4 SLI-DR
256MB BFG 7800GTX OC
1GB OCZ Gold 2x512 DC PC3200

It's Not That We Don't Know, It's That We Don't Do What We Do Know
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:06 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.