In: Computer Science
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]
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;
}