Understanding bool functions in product comparison?

In summary, a bool function is a mathematical function that takes boolean values as input and returns a boolean value as output. They are used in various scientific fields to model logical operations, analyze data, and make predictions. The main difference between a bool function and a regular function is that a bool function only returns boolean values, while a regular function can return any type of value. To create a bool function, you need to define the input parameters and logical operations, and use conditional statements to determine the output. An example of a bool function is the logical AND function, which returns true if both inputs are true.
  • #1
torquerotates
207
0

Homework Statement



I'm given the member function:

bool Product::is_better_than(Product b) const
{
if(price==0) return true;
if (b.price price==0) return false;
return score/price>b.score/b.price;
}

I'm really confused about the last line "return score/price>b.score/b.price;". Does it mean, return true if ">" holds and return false if "<" doesn't hold?
 
Physics news on Phys.org
  • #2
Yes. You can think of all comparisons as functions that return true or false depending on whether the condition is satisfied.
 
  • #3
oh I see. Thanks
 

1. What is a bool function?

A bool function, short for boolean function, is a mathematical function that takes one or more boolean values (true or false) as input and returns a single boolean value as output.

2. How are bool functions used in science?

Bool functions are used in various scientific fields, including computer science, mathematics, and physics. They are often used to model logical operations, analyze data, and make predictions based on given inputs.

3. What is the difference between a bool function and a regular function?

The main difference is that a bool function only returns a boolean value (true or false) while a regular function can return any type of value. Additionally, bool functions are often used to evaluate conditions and make decisions in programs, whereas regular functions can perform a wide range of tasks.

4. How do you create a bool function?

To create a bool function, you will need to define the input parameters and the logical operations that will be performed on those inputs. You can then use conditional statements, such as if/else statements, to determine the output based on the given inputs.

5. Can you give an example of a bool function?

One example of a bool function is the logical AND function, which takes two boolean values as input and returns true if both inputs are true, and false otherwise. So, if we have a bool function called "isRaining", we can use the logical AND function to determine if it is both raining and windy by writing "isRaining(true) and isWindy(true)". This will return true only if both conditions are met.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
4K
  • Programming and Computer Science
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
859
  • Engineering and Comp Sci Homework Help
Replies
8
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Programming and Computer Science
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
945
Back
Top