Question

In: Computer Science

1.    Given the following values, evaluate the logical value of each expression.   [3 each] int a...

1.    Given the following values, evaluate the logical value of each expression.   [3 each]

int a = 3;

int b = 8;

int c = 3;

int d = 10;

              a.            b < c && c < d

              b.           !(a == c && c != d)

c.            !(d <= b) || (c > a)

d.           a == c || c == d


2.           Given the following values, evaluate the logical value of each expression.   [4 each]

int g = 6;

int h = 8;

int i = 6;

int j = 15;

              a.            (i == g || g < i) || j == h

      b.           h > j || g != i && i != h

Bonus.   How would the logical test of a ≤ b ≤ c be written in C++? [1]

Solutions

Expert Solution


Values for a, b,c ,d given as a = 3, b = 8, c = 3, d = 10;

solving each expression

1. b < c && c < d ==> Answer : false

   subex1 : b < c ==> 8 < 3 ==> false
   subex2 : c < d ==> 3 < 10 ==> true

expression : subex1 && subex2 == > false && true == > false

2. !(a == c && c != d)       ==> Answer : false

   subex1 : a == c ==> 3 == 3 ==> true
   subex2 : c != d ==> 3 != 10 ==> true
   subex3 : subex1 && subex2 ==> true

expression : ! subex3 ==> false

3. !(d <= b) || (c > a)       ==> Answer : true

   subex1 : d <= b ==> 10 <= 8 ==> false
   subex2 : c > a ==> 3 > 3 ==> false
   subex3 : subex1 !! subex2 ==> false

expression : ! subex3 ==> true

4. a == c || c == d           ==> Answer : true

   subex1 : a == c ==> 3 == 3 ==> true
   subex2 : c == d ==> 3 == 10 ==> false
  
expression : subex1 && subex2 == > true || false == > true


Values for g, h, i, j given as g = 6, h = 8, i = 6, j = 15;

1. (i == g || g < i) || j == h     == > Answer : true

subex1 : i == g ==> 6 == 6 ==> true
subex2 : g < i ==> 6 < 6 ==> false
subex3 : subex1 || subex2 == > true || false ==> true
subex4 : j == h ==> 15 == 8 ==> false

expression : subex3 || subex4 ==> true || false ==> true

2. h > j || g != i && i != h       ==> Answer : false

subex1 : h > j    ==> 8 > 15 ==> false
subex2 : g != i ==> 6 != 6 ==> false
subex3 : i != h   ==> 6 != 8 ==> true

expression : subex1 || subex2 && subex3 ==> false || false && true ==> false

C++ Code for logical test pf a ≤ b ≤ c is as follows


// include iostream
#include <iostream>

// main to execute dode
int main() {
    
    // initialization of a, b, c, d
    int a = 3;
    int b = 8;
    int c = 3;
    int d = 10;
    
    // given express
    bool value = (a <= b <= c);
    // str will be "true" if value is 1 otherwise it will be "false"
    std::string str = (value ? "true" : "false");
    // print value
    std::cout << " logical value of (a <= b <= c) expression : " << str;

    return 0;
}



Related Solutions

Evaluate the following logical expression. Choose True if the expression evaluates to true; choose False if...
Evaluate the following logical expression. Choose True if the expression evaluates to true; choose False if the expression evaluates to false. (3 * 5 > 10) || (20 < 15) True False Evaluate the following logical expression. Choose True if the expression evaluates to true; choose False if the expression evaluates to false. "Medium" < "High" True False Evaluate the following logical expression. Choose True if the expression evaluates to true; choose False if the expression evaluates to false. (4...
create a program in java that will evaluate a logical expression (compound proposition) based on the...
create a program in java that will evaluate a logical expression (compound proposition) based on the given truth values of individual propositional variables. The logical expression may include the logical AND or the logical OR operators. The NOT operator will be included in the variable names itself. So, a proposition such as ¬a would appear as na in the logical expression. Here is an example of a logical expression using proper notation: a ∧ b ∨ ¬c ∨ d This...
1. Which of the following can be treated as a Boolean expression? A. an int expression...
1. Which of the following can be treated as a Boolean expression? A. an int expression B. any of these C. the result of a comparison(such as <or>) D. a float expression 2. Assuming the variable x contains an integer value what will the result of the following statement be: if x<0 or x>=0. A. True B. False C. Sometimes true and sometimes false D. A "math domain" error will occur
GIVEN THE FOLLOWING PSOSTFIX EXPRESSION, SHOW TO USE A STACK TO EVALUATE ITS FINAL VALUE. SHOW...
GIVEN THE FOLLOWING PSOSTFIX EXPRESSION, SHOW TO USE A STACK TO EVALUATE ITS FINAL VALUE. SHOW STACK CONFIGURATION DETAILS 20 3 18 8 - * 10 + +10 12 - /
Evaluate the truth values of the following conditions given the values of the declared variables. NOTE:...
Evaluate the truth values of the following conditions given the values of the declared variables. NOTE: Conditions formed using relational or equality operators (>, <, >=, <=, ==, !=) are relational conditions. Conditions formed using logical operators [&& (AND), || (OR), & (boolean AND), | (boolean inclusive OR), ^ (boolean exclusive OR) are complex conditions. Variables boolean gameLoss = false; int points = 15; boolean championship = false; Conditions: Evaluate then Indicate the truth value produced by the relational conditions...
     i What values would be stored in the given variables in each case? a.          int n =...
     i What values would be stored in the given variables in each case? a.          int n = 12 % 5; b.          double x = 15 % 11 + 5.3 - 5 / (2.5 - 0.3); c.   float y = 2 / (3.5 + static_cast<int>(3.5)); d.   bool z = (6 – 7 <= 2 * 1) && (5 + 4 >= 3) || (6 + 2 != 17 – 3 * 10);
Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4...
Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4 – 9 b) ( 2 + 6 ) / ( 3 – 5 ) . Algorithm WRITE STEP BY STEP Scan the characters in the infix expression. While there are characters left in the infix expression: Check the next character in the expression. 1. If the next character is operand, remove it from the expression and push it onto the operand stack. 2. If...
Given an int variable k, write an expression whose value is the k-th character in the String variable word.
1. Given an int variable k, write an expression whose value is the k-th character in the String variable word. Assume thatword has been initialized and that the value ofk is non-negative and less than the length ofword.Example 1: if k's value is 3 andword is "spring", the value of the expression would be 'i'.Example 2: if k's value is 0 andword is "fall", the value of the expression would be 'f'.2. Given an int variable k, write an expression whose...
Show step-by-step how Java will evaluate the following expression: 8 % 3 + 3 % 2...
Show step-by-step how Java will evaluate the following expression: 8 % 3 + 3 % 2 – 9 % 2.0 * 5 15/15 % 7 *2   – 11. /4 * 5
For the following exercises, compute the value of the expression. C(26, 3)
For the following exercises, compute the value of the expression.  C(26, 3)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT