Lab04_3.cpp is provided. The program demonstrates increasingly complex Boolean e
ID: 3730821 • Letter: L
Question
Lab04_3.cpp is provided. The program demonstrates increasingly complex Boolean expressions. Study the program. The last part of the program, marked with the comment “table question starts here” (line 54), takes five input values from the user, and calculates and displays the results of two complex Boolean expressions. Complete the leftmost five columns of the following table; think of sets of five input values that generate the corresponding expected result shown in the table. Test and record actual results.
Input
Expected Result
Actual Result
A
B
C
P
Q
Expr 1
Expr 2
Expr 1
Expr 2
True
True
True
False
False
True
False
False
// Lab04_3.cpp
// Demonstration of increasingly complex boolean expressions
// YOUR NAME:
// CCCC CSC120 Fall 2009
// DATE:
#include <iostream>
using namespace std;
int main()
{
// define and initialize variables to use as operands
int A = 5;
int B = 4;
int C = 3;
bool P = true;
bool Q = false;
// define variable to use as result
bool bResult;
// Arrange for console insertions and keyboard extractions of Boolean values as
// true or false, rather than as 1 or 0. This will persist through the program.
cout << boolalpha;
cin >> boolalpha;
// now demonstrate increasingly complex expressions
bResult = true;
cout << true << " evaluates to " << bResult << endl;
bResult = Q || true;
cout << Q << " || " << true << " evaluates to " << bResult << endl;
bResult = P && P;
cout << P << " && " << P << " evaluates to " << bResult << endl;
bResult = C < A;
cout << C << " < " << A << " evaluates to " << bResult << endl;
bResult = (C > A) || P;
cout << "(" << C << " > " << A << ")" << " || " << P
<< " evaluates to " << bResult << endl;
// note: in C++, the following expression is _not_ written like this:
// C < B < A
bResult = (C < B) && (B < A);
cout << "(" << C << " < " << B << ")" << " && "
<< "(" << B << " < " << A << ")"
<< " evaluates to " << bResult << endl;
// table question starts here
// prompt for and extract input to be used in evaluating
// the two following expressions
cout << "Provide integer values for A, B and C: " << endl;
cin >> A >> B >> C;
cout << "Provide Boolean values (true or false) for P and Q: " << endl;
cin >> P >> Q;
// two expressions for the table
bResult = (A < B) && (B < C) && (P || Q);
cout << "Expr 1 evaluates to " << bResult << endl;
bResult = ((A < C) || (B < C)) && !P && (((A < C) && Q) || (!(A < C) && !Q));
cout << "Expr 2 evaluates to " << bResult << endl;
return 0;
} // end function main
Input
Expected Result
Actual Result
A
B
C
P
Q
Expr 1
Expr 2
Expr 1
Expr 2
True
True
True
False
False
True
False
False
Explanation / Answer
Given Expressions are :
bResult = (A < B) && (B < C) && (P || Q);
cout << "Expr 1 evaluates to " << bResult << endl;
bResult = ((A < C) || (B < C)) && !P && (((A < C) && Q) || (!(A < C) && !Q));
cout << "Expr 2 evaluates to " << bResult << endl;
Based on above 2 expressions value of A,B,C,P and Q that satisfied the expected result are given below in table.
You can execute the program by putting these values in variables.
A B C P Q Expr1(Expected) Expr2(Expected) Expr1(Actual) Expr2(Actual) 2 3 4 False True True True True True 2 3 4 True True True False True False 4 3 5 False True False True False True 4 3 5 True True False False False FalseRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.