Following is a list of some Boolean expressions. Carefully go through each one of them and determine whether they evaluate to true or false.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Following is a list of some Boolean expressions. Carefully go through each one of them and determine whether they evaluate to true or false. Expression Answer A: ( (count == 0) && (limit < 20)) B: ( count == 0 && limit < 20 ) C: ( (limit > 12) || (count < 5) ) D: ( !(count == 5) ) E: ( (count == 1) && (x < y) ) F: ( (count < 10) || (x < y) ) G: ( !( ((count < 10) || (x < y)) && (count >= 0)) ) H: ( ((limit/count) > 7) || (limit < 20) ) I: ( (limit < 20) || ((limit/count)> 7) ) J: ( ((limit/count) > 7) && (limit < 0) ) K: ( (limit < 0) && (( limit/count) > 7) ) L: ( (5 && 7) + (!6) ) Now, create a file ex41.cpp and cut and paste the following program in it. Compile and run the program and see how well your answers to the above expressions match the program's output. // ex41.cpp - This program illustrates the Boolean expressions and the // order of precedence #include<iostream> using namespace std; int main() { int count = 0, limit = 10; int x,y; cout << "a " << ( (count == 0)&& (limit < 20)) << "\n"; cout << "b " << ( count == 0 && limit < 20 ) << "\n"; cout << "c " << ( (limit > 12) || (count < 5) ) << "\n"; cout << "d " << ( !(count == 5) ) << "\n"; cout << "e " << ( (count == 1)&& (x < y) ) << "\n"; cout << "f " << ( (count < 10) || (x < y) ) << "\n"; cout << "g " << ( !( ((count < 10) || (x < y)) && (count >= 0)) ) << "\n"; cout << "h " << ( ((limit/count)> 7) || (limit < 20) ) << "\n"; cout << "i " << ( (limit < 20) || ((limit/count) > 7) ) << "\n"; cout << "j " << ( ((limit/count)> 7) && (limit < 0) ) << "\n"; cout << "k " << ( (limit < 0) && (( limit/count) > 7) ) << "\n"; cout << "l " << ( (5 && 7) + (!6) ) << "\n"; return 0; } Write your answers through comments. Note that some of the statements may cause run-time errors. Find those statements and explain why the errors have happened. To make the program go to the next statement, simply comment (//) the line that causes the run-time error. Recompile and run the program again until all lines that cause a run-time error are commented. What is the difference between h and i? Would it make any difference if in "j" we switch the first and the second statements, i.e., we use: cout << "j " << ( (limit < 0) && ((limit/count) > 7) ) << "\n";

Exercise 4.1
Following is a list of some Boolean expressions. Carefully go through each one of them and
determine whether they evaluate to true or false.
Expression
A: ((count=0) && (limit <20))
B: (count == 0 && limit <20)
C: ((limit > 12) || (count <5))
D: (!(count=5))
E: ((count == 1) && (x<y))
F: ((count <10)| (x<y))
G: (!(((count <10) || (x<y))&& (count >= 0)))
H: (((limit/count) >7) || (limit <20))
I: ((limit <20) || ((limit/count)> 7))
J: (((limit/count) >7) && (limit < 0))
K: ((limit <0)&&((limit/count) > 7))
L: ((5 && 7) + (16))
Now, create a file ex41.cpp and cut and paste the following program in it. Compile and run
the program and see how well your answers to the above expressions match the program's
output.
// ex41.cpp - This program illustrates the Boolean expressions and the
// order of precedence
#include<iostream>
using namespace std;
Answer
int main()
{
int count = 0, limit= 10;
int x,y:
cout << "a "<<((count == 0)&& (limit <20)) << "\n";
cout << "b"<<(count == 0 && limit <20) << "\n";
cout << "e "<<((limit > 12) || (count <5) ) << "\n"
cout << "d" <<(!(count=5)) << "\n";
cout << "e "<<((count == 1)&& (x<y)) << "\n";
cout << "f "<<((count <10) || (x<y)) << "\n";
cout << "g "<<(!(((count <10) || (x<y)) && (count >= 0))) << "\n";
cout << "h"<<(((limit/count)> 7) || (limit <20)) << "\n";
cout << "i "<<((limit <20) || ((limit/count) > 7)) << "\n";
cout << "j"<<(((limit/count)> 7) && (limit < 0)) << "\n";
cout << "k"<<((limit < 0) && (( limit/count) > 7)) << "\n";
cout << "1 "<<((5 && 7) + (!6) ) << "\n";
return 0;
}
Write your answers through comments.
Transcribed Image Text:Exercise 4.1 Following is a list of some Boolean expressions. Carefully go through each one of them and determine whether they evaluate to true or false. Expression A: ((count=0) && (limit <20)) B: (count == 0 && limit <20) C: ((limit > 12) || (count <5)) D: (!(count=5)) E: ((count == 1) && (x<y)) F: ((count <10)| (x<y)) G: (!(((count <10) || (x<y))&& (count >= 0))) H: (((limit/count) >7) || (limit <20)) I: ((limit <20) || ((limit/count)> 7)) J: (((limit/count) >7) && (limit < 0)) K: ((limit <0)&&((limit/count) > 7)) L: ((5 && 7) + (16)) Now, create a file ex41.cpp and cut and paste the following program in it. Compile and run the program and see how well your answers to the above expressions match the program's output. // ex41.cpp - This program illustrates the Boolean expressions and the // order of precedence #include<iostream> using namespace std; Answer int main() { int count = 0, limit= 10; int x,y: cout << "a "<<((count == 0)&& (limit <20)) << "\n"; cout << "b"<<(count == 0 && limit <20) << "\n"; cout << "e "<<((limit > 12) || (count <5) ) << "\n" cout << "d" <<(!(count=5)) << "\n"; cout << "e "<<((count == 1)&& (x<y)) << "\n"; cout << "f "<<((count <10) || (x<y)) << "\n"; cout << "g "<<(!(((count <10) || (x<y)) && (count >= 0))) << "\n"; cout << "h"<<(((limit/count)> 7) || (limit <20)) << "\n"; cout << "i "<<((limit <20) || ((limit/count) > 7)) << "\n"; cout << "j"<<(((limit/count)> 7) && (limit < 0)) << "\n"; cout << "k"<<((limit < 0) && (( limit/count) > 7)) << "\n"; cout << "1 "<<((5 && 7) + (!6) ) << "\n"; return 0; } Write your answers through comments.
Write your answers through comments.
Note that some of the statements may cause run-time errors. Find those statements and explain why
the errors have happened. To make the program go to the next statement, simply comment (//) the
line that causes the run-time error. Recompile and run the program again until all lines that cause a
run-time error are commented.
What is the difference between h and i?
Would it make any difference if in "j" we switch the first and the second statements, i.e., we use:
cout << "j "<<((limit < 0) && ((limit/count) >7) ) << "\n";
Transcribed Image Text:Write your answers through comments. Note that some of the statements may cause run-time errors. Find those statements and explain why the errors have happened. To make the program go to the next statement, simply comment (//) the line that causes the run-time error. Recompile and run the program again until all lines that cause a run-time error are commented. What is the difference between h and i? Would it make any difference if in "j" we switch the first and the second statements, i.e., we use: cout << "j "<<((limit < 0) && ((limit/count) >7) ) << "\n";
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education