Chapter 3 Flashcards

1
Q

define boolean expression

A

an expression that evaluates to a boolean value: true or false.

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

define boolean expression

A

an expression that evaluates to a boolean value: true or false.

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

What is the operator for less than?

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

What is the operator for less than or equal to?

A

<=

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

What is the operator for greater than?

A

>

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

What is the operator for greater than or equal to?

A

> =

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

which is correct => or >= ?

A

> =

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

what is the operator for equal to?

A

==

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

what is the operator for not equal to?

A

!=

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

Which is correct != or =! ?

A

!=

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

what is the bool data type used for?

A

it is used for declaring boolean variables

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

____ and ___ are boolean literals

A

true and false

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

____ statements executes an action if and only if the condition is true

A

if

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

____ statements executes an action if and only if the condition is true

A

if

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

what is the syntax for an if-else statement?

A
if (boolean-expression)
{ 
statement(s)-for-the-true-case;
}
else
{ 
statement(s)-for-the-false-case;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the operator for less than or equal to?

A

<=

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

what function can you use to generate a random integerr?

A

rand( )

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

What is the operator for greater than or equal to?

A

> =

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

which is correct => or >= ?

A

> =

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

what is the operator for equal to?

A

==

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

what is the operator for not equal to?

A

!=

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

Which is correct != or =! ?

A

!=

23
Q

what is the bool data type used for?

A

it is used for declaring boolean variables

24
Q

____ and ___ are boolean literals

A

true and false

25
Q

what happens if you assign a number to bool?

A

any non zero digit reads true and 0 reads false

26
Q

____ statements executes an action if and only if the condition is true

A

if

27
Q

what is the syntax for a if statement?

A

if (boolean-expression)
{
statement(s);
}

28
Q

what is the syntax for an if-else statement?

A
if (boolean-expression)
{ 
statement(s)-for-the-true-case;
}
else
{ 
statement(s)-for-the-false-case;
}
29
Q

you cannot test the equality of two ____ numbers

A

floating-point

30
Q

what function can you use to generate a random number?

A

rand( )

31
Q

what header file is rand( ) defined under?

A

cstdlib

32
Q

what is the value of RAND_MAX?

A

32767

33
Q

the rand( ) function displays a integer between _____ and ___

A

0 and RAND_MAX (32767)

34
Q

what is meant when it is said that rand( ) is pseudo random?

A

the random function produces the same sequence of numbers every time it is executed on the same system

35
Q

when evaluating (p1 || p2) if p1 is true does the program read p2?

A

no

36
Q

how can you change the seed?

A

use srand(seed)

37
Q

what header file is srand( ) under?

A

cstdlib

38
Q

what is a way in which you can get a different sequnce of random numbers every time using the rand( ) function?

A

use srand with time(0) as the seed

39
Q

what header file is time( ) stored under?

A

ctime

40
Q

what is the operator for not?

A

!

41
Q

what is the operator for and?

A

&&

42
Q

what is the operator for or?

A

||

43
Q

what does the not (!) operator do?

A

negates the true to be false and the false to be true

44
Q

what does the and (&&) operator do?

A

reads true if and only if all the boolean operands are true

45
Q

what does the or (||) operator do?

A

reads true if any of the boolean operands are true

46
Q

is this correct c++ syntax?

1<= numberOfDaysInAMonth<=31

A

no, this would produce a logic error. the following is the correct statement
(1<=numberOfDaysInAMonth) && (31 >= numberOfDaysInAMonth)

47
Q

when evaluating (p1 && p2) if p1 is false does the program read p2?

A

no

48
Q

when evaluating (p1 || p2) if p1 is true does the program read p2?

A

no

49
Q

a switch statement checks ____ the cases abd executes the statements in the ____ ____

A

all

matched cases

50
Q

what is the syntax for a switch statement?

A
switch (switch-expression)
{
case value 1: statement(s)1;break;
case value 2: statement(s)2;break;
.......
case value n: statement(s)n;break;
default: statement(s)-for-default;
}
51
Q

in switch expressions the variable must always be ____

A

an integer

52
Q

when the value in a case statement matches the value of a switch expression the statements starting from that case are executed until

A

either a break statement or the end of the switch statement is reached

53
Q

what is the syntax of a conditional expression for an if else statement

A

boolean expression ? expression1 : expression 2

where ? acts as if and : acts else

54
Q

what is the only ternary operator in C++ and why is it a ternary operator

A

the conditional expression formed by ? and :

it is ternary becayse it uses three operands