If (age =65) AND rating =”g” then ouput “Discount” end if — written c++
Here is the equivalent C++ code for the given pseudocode:
“`cpp
if ((age = 65) && rating == “g”) {
std::cout << "Discount" <= 18 AND age 10 AND Y > 10 — why not if X AND Y > 10 then ?
The expression `if x > 10 AND y > 10` checks that both `x` and `y` are greater than 10 individually, which is logically correct.
However, `if x AND y > 10` would not work as intended for the following reasons:
1. **Ambiguity in evaluation**: `x AND y > 10` would first evaluate `y > 10`, returning a boolean value (`true` or `false`), and then evaluate `x AND (result of y > 10)`. This is not the same as checking whether both `x` and `y` are greater than 10.
2. **Logical expression issue**: In most programming languages, `AND` is used to combine two conditions. In your example, `if x AND y > 10` would not compare `x` and `y` to 10 as expected; instead, it could result in unintended behavior (like checking the truthiness of `x` combined with a comparison of `y` to 10).
To check that both `x` and `y` are greater than 10, you need to explicitly compare both variables to 10, as in `if x > 10 AND y > 10`.
Which of the following must always be false : e>12 and e12 or f>12,
Let’s evaluate each of the conditions:
1. **`e > 12 AND e < 15`**:
This condition will be **true** if `e` is between 12 and 15, exclusive (i.e., 12 < `e` 12 OR f > 12`**:
This condition will be **true** if either `e > 12` or `f > 12`. If either of these conditions is satisfied, it will be true. For example, if `e = 13`, the condition is true. So, this **does not always have to be false** either.
### Conclusion:
None of the conditions **must always be false**, because each one can be true under specific circumstances.
if a true,b true c false, which expression is true a or b and c, a and b and c, a and b or c, two of above
Let’s break down each expression based on the truth values for **a = true**, **b = true**, and **c = false**:
1. **`a OR b AND c`**:
– `b AND c` will be **false** because `c` is false.
– `a OR (b AND c)` becomes `true OR false`, which is **true**.
2. **`a AND b AND c`**:
– This checks if all are true. Since `c` is false, the whole expression is **false**.
3. **`a AND b OR c`**:
– `a AND b` will be **true** because both `a` and `b` are true.
– `a AND b OR c` becomes `true OR false`, which is **true**.
### Conclusion:
The expressions that are **true** are:
– `a OR b AND c`
– `a AND b OR c`
So, the answer is **”two of the above”**.