logical expressions Flashcards

1
Q

Logical Expressions

- Used to ‘logically’ compare

A

letters, numbers, symbols, variables, constants, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When a logical expression is ‘evaluated’ the answer

A

will either be TRUE or FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Logical expressions are surrounded

A

by parenthesis ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A logical expression should be read

A

like a question

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Logical expressions are used in

A

Selection and Repetition statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Simple Logical Operators

A

Used in a single logical expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

!=

A

(Inequality)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

SIGN**

A

> (Greater than)
>= (Greater than or equal to)
< (Less than)
<= (Less than or equal to)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Complex Logical Operators

A

Used for combining one or more logical expressions)

&& (Logical AND) - This key is found above the ‘7’ key when holding the ‘Shift’ key
|| (Logical OR) - This key is found above the ‘Enter’ key when holding the ‘Shift’ key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Examples:
	 (9 > 5)			?
	 (x <= 20)			?
	 (a < b + c)		?
	 (grade != 'F')     ?
	 (name == "Mark")   ?
	 (gpa > 2.5)        ?
 ( (score <= 0)  && (score <= 100) )	?
 ( (temp < 32) || (temp > 95) )		?
A
int x = 15;
	int a = 5, b = 6, c = 7;
	char grade = 'F';
	string name = "Joe";
	double gpa = 3.8;
	int score = 81;
	double temp = 61;
	bool result = 0;
 result = (9 > 5);
 cout << "1) " << result << endl;

 result =  (x <= 20);
 cout << "2) " << result << endl;

 result = (a < b + c);
 cout << "3) " << result << endl;

 result = (grade != 'F');
 cout << "4) " << result << endl;

 result = (name == "Mark");
 cout << "5) " << result << endl;

 result = (gpa > 2.5);
 cout << "6) " << result << endl;

 result = (score <= 0  && score <= 100);
 cout << "7) " << result << endl;

 result = (temp < 32 || temp > 95);
 cout << "8) " << result << endl;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly