Question

In: Computer Science

Suppose that the double variables a, b and c contain the values -10, 0 1 and2...

Suppose that the double variables a, b and c contain the values -10, 0 1 and2 1 respectively, and the boolean variables b1, b2 and b3 contain the values true, false and false respectively Is each of the following expressions legal or illegal and what will the result be?

a) a> b || b>c

b) b1 | | b2 && b3

Solutions

Expert Solution

The expressions are legal and the result or output will be:

For a) a>b||b>c

In the first expression there are relational operators which have a higher precedence than( || operator know as Logical OR Operator ) so first the logical operators evaluate

a>b is false or we can say it as 0 (default numeric value of false is 0)

b>c is false or we can say it is 0( default numeric value of false is 0)

After that false || false is false or we can say it is 0(default numeric value of false is 0)

So the result for expression a) will be 0(i.e false)

Now

b) b1||b2&&b3

Here in this expression there are two operators Logical OR(||) and Logical AND(&&)

Logical AND has a higher precedence than Logical OR

So b2 && b3 will calculate first

b2= false

b3= false

So false && false is false

Now the Logical OR operation will be done

Previous result false(b2&& b3)

b1= true

So true || false is true or we can say it is 1(default numeric value of true is 1)

So the result for expression b) will be 1(i.e true)

----------------------------------------------------------------------------------------------------

Now i am giving the c++ language code for further clarification:

#include <iostream>

using namespace std;

int main()
{
double a = -10,b=01,c=21;
bool b1=true,b2= false,b3= false;
  
cout<<"Expression a) a>b||b>c Result : "<<(a>b||b>c)<<endl;
cout<<"Expression b) b1||b2&&b3 Result : "<<(b1||b2&&b3);
  

return 0;
}

Output:


Related Solutions

1. Suppose the random variable A is determined by three variables, B, C, and u in...
1. Suppose the random variable A is determined by three variables, B, C, and u in the following way: A = β0 + β1B + β2C + u Where the following relationships hold: • Cov(A,B)=10 • Cov(B,C)=40 • Var(B)=100 • Cov(B,u) = 0 and Cov(C,u) = 0 Finally, suppose that β2 = 3. (a) You take a random sample of observations of A and B and estimate theregression: A = β0 + β1B + ε which omits C. Find E[βˆ1]...
Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double area = 0;     area = width * length;     cout << "\n***maxArea called" << endl;          cout << "***       rectangleCount = " << Rectangle::rectangleCount << endl << endl;    } Compete this code to find the maximum area of rectangle between a,b,c
Stock Expected Dividend Expected Capital Gain A $0 $10 B 5 5 C 10 0 a....
Stock Expected Dividend Expected Capital Gain A $0 $10 B 5 5 C 10 0 a. If each stock is priced at $100, what are the expected net percentage returns on each stock to (i) a pension fund that does not pay taxes, (ii) a corporation paying tax at 45% (the effective tax rate on dividends received by corporations is 10.5%), and (iii) an individual with an effective tax rate of 10% on dividends and 5% on capital gains? (Do...
Write in C++ and insert comments. Input two values a and b 0 may be used...
Write in C++ and insert comments. Input two values a and b 0 may be used for False 1 may be used for True Write a program that will print the truth table for the logical operator and give the results for the specific input a, b. The following logical operators should be coded. ● conjunction (AND) ● disjunction (OR) ● conditional Statement (If a then b) ● exclusive OR (XOR) ● biconditional operation (p iff q) Example for conjunction...
a b c d f 0 0 0 0 0 0 0 0 1 0 0...
a b c d f 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 0 1...
DATA: Grades A- 10     B- 2     C- 1 D- 0   F- 2 Q23. a)...
DATA: Grades A- 10     B- 2     C- 1 D- 0   F- 2 Q23. a) If a committee with 2 student members is to be formed, what is the probability of forming a committee with one A grade and one F grade student? Q24. If a committee with 3 student members is to be formed, what is the probability of forming a committee with two A grade and one B grade student? Q25.If the records show that, the probability...
Suppose that a block can contain at most four data values and that all data values...
Suppose that a block can contain at most four data values and that all data values are integers. Using only B+ trees of degree 2, give examples of each of the following : a. A B+ tree whose height changes from 2 to 3 when the value 42 is inserted. Show your structure before and after the insertion. b. A B+ tree in which the deletion of the value 42 leads to a redistribution. Show your structure before and after...
Let X and Y be random variables. Suppose P(X = 0, Y = 0) = .1,...
Let X and Y be random variables. Suppose P(X = 0, Y = 0) = .1, P(X = 1, Y = 0) = .3, P(X = 2, Y = 0) = .2 P(X = 0, Y = 1) = .2, P(X = 1, Y = 1) = .2, P(X = 2, Y = 1) = 0. a. Determine E(X) and E(Y ). b. Find Cov(X, Y ) c. Find Cov(2X + 3Y, Y ).
Suppose that ac + bd = 0. Show that vectors [a, b] and [c, d] are...
Suppose that ac + bd = 0. Show that vectors [a, b] and [c, d] are perpendicular. The number ac + bd is called the dot product of the vectors [a, b] and [c, d].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT