#include #include using namespace std; int main() { /* * Logical AND Truth Table */ cout << "Logical AND Truth Table" << endl; bool a, b, c; cout << "a\tb\tc = a AND b" << endl; a = false; b = false; c = a && b; cout << a << "\t" << b << "\t" << c << endl; a = false; b = true; c = a && b; cout << a << "\t" << b << "\t" << c << endl; a = true; b = false; c = a && b; cout << a << "\t" << b << "\t" << c << endl; a = true; b = true; c = a && b; cout << a << "\t" << b << "\t" << c << endl; getch(); /* * Logical OR Truth Table */ cout << endl << "Logical OR Truth Table" << endl; cout << "a\tb\tc = a OR c" << endl; a = false; b = false; c = a || b; cout << a << "\t" << b << "\t" << c << endl; a = false; b = true; c = a || b; cout << a << "\t" << b << "\t" << c << endl; a = true; b = false; c = a || b; cout << a << "\t" << b << "\t" << c << endl; a = true; b = true; c = a || b; cout << a << "\t" << b << "\t" << c << endl; getch(); /* * Logical NOT Truth Table */ cout << endl << "Logical NOT Truth Table" << endl; cout << "a\tc = NOT a" << endl; a = false; c = !a; cout << a << "\t" << c << endl; a = true; c = !a; cout << a << "\t" << c << endl; getch(); /* * Comparison Operators ==, <, <=, >, >= */ cout << endl << "Comparison Operators ==, <, <=, >, >=" << endl; int x=21, y=21, z=42; bool xEqualsY = x == y; bool xGreaterThanY = x > y; bool xGreaterOrEqualsY = x >= y; bool xLessThanY = x < y; bool xLessThanOrEqualsY = x <= y; cout << "Comparing x and y" << endl; cout << "x = " << x << ",\ty = " << y<< endl; cout << "x == y\t" << x << " == " << y << ": " << xEqualsY << endl; cout << "x > y\t" << x << " > " << y << ": " << xGreaterThanY << endl; cout << "x >= y\t" << x << " >= " << y << ": " << xGreaterOrEqualsY << endl; cout << "x < y\t" << x << " < " << y << ": " << xLessThanY << endl; cout << "x <= y\t" << x << " <= " << y << ": " << xLessThanOrEqualsY << endl; getch(); bool xEqualsZ = x == z; bool xGreaterThanZ = x > z; bool xGreaterOrEqualsZ = x >= z; bool xLessThanZ = x < z; bool xLessThanOrEqualsZ = x <= z; cout << "\nComparing x and z" << endl; cout << "x = " << x << ",\tz = " << z<< endl; cout << "x == z\t" << x << " == " << z << ": " << xEqualsZ << endl; cout << "x > z\t" << x << " > " << z << ": " << xGreaterThanZ << endl; cout << "x >= z\t" << x << " >= " << z << ": " << xGreaterOrEqualsZ << endl; cout << "x < z\t" << x << " < " << z << ": " << xLessThanZ << endl; cout << "x <= z\t" << x << " <= " << z << ": " << xLessThanOrEqualsZ << endl; getch(); /* * Comparing To Constants */ cout << endl << "Comparing To Constants" << endl; int age = 15; const int MIN_DRIVING_AGE = 16; bool canDrive = age >= MIN_DRIVING_AGE; cout << "age = " << age << ",\tMIN_DRIVING_AGE = " << MIN_DRIVING_AGE << endl; cout << "canDrive = age >= MIN_DRIVING_AGE: " << canDrive << endl; getch(); /* * Bank Example */ cout << endl << "Bank Example" << endl; const int WITHDRAWAL = 0; const int DEPOSIT = 1; const float MAX_WITHDRAWAL = 500.0; double balance = 100.0; int transaction = WITHDRAWAL; double withdrawal = 200.0; bool withdrawing, depositing, notEnough; withdrawing = transaction == WITHDRAWAL; depositing = transaction == DEPOSIT; cout << "MAX_WITHDRAWAL:\t" << MAX_WITHDRAWAL << endl; cout << "balance:\t" << balance << endl; cout << "withdrawing:\t" << withdrawing << endl; cout << "depositing:\t" << depositing << endl; cout << "withdrawal:\t" << withdrawal << endl; notEnough = withdrawal >= MAX_WITHDRAWAL; cout << "notEnough:\t" << notEnough << "\twithdrawal >= MAX_WITHDRAWAL" << endl; notEnough = withdrawal > balance; cout << "notEnough:\t" << notEnough << "\twithdrawal > balance" << endl; notEnough = (withdrawal >= MAX_WITHDRAWAL) || (withdrawal > balance); cout << "notEnough:\t" << notEnough << "\t(withdrawal >= MAX_WITHDRAWAL) || (withdrawal > balance)" << endl; getch(); }