Chapter 3 Flashcards
define boolean expression
an expression that evaluates to a boolean value: true or false.
define boolean expression
an expression that evaluates to a boolean value: true or false.
What is the operator for less than?
What is the operator for less than or equal to?
<=
What is the operator for greater than?
>
What is the operator for greater than or equal to?
> =
which is correct => or >= ?
> =
what is the operator for equal to?
==
what is the operator for not equal to?
!=
Which is correct != or =! ?
!=
what is the bool data type used for?
it is used for declaring boolean variables
____ and ___ are boolean literals
true and false
____ statements executes an action if and only if the condition is true
if
____ statements executes an action if and only if the condition is true
if
what is the syntax for an if-else statement?
if (boolean-expression) { statement(s)-for-the-true-case; } else { statement(s)-for-the-false-case; }
What is the operator for less than or equal to?
<=
what function can you use to generate a random integerr?
rand( )
What is the operator for greater than or equal to?
> =
which is correct => or >= ?
> =
what is the operator for equal to?
==
what is the operator for not equal to?
!=
Which is correct != or =! ?
!=
what is the bool data type used for?
it is used for declaring boolean variables
____ and ___ are boolean literals
true and false
what happens if you assign a number to bool?
any non zero digit reads true and 0 reads false
____ statements executes an action if and only if the condition is true
if
what is the syntax for a if statement?
if (boolean-expression)
{
statement(s);
}
what is the syntax for an if-else statement?
if (boolean-expression) { statement(s)-for-the-true-case; } else { statement(s)-for-the-false-case; }
you cannot test the equality of two ____ numbers
floating-point
what function can you use to generate a random number?
rand( )
what header file is rand( ) defined under?
cstdlib
what is the value of RAND_MAX?
32767
the rand( ) function displays a integer between _____ and ___
0 and RAND_MAX (32767)
what is meant when it is said that rand( ) is pseudo random?
the random function produces the same sequence of numbers every time it is executed on the same system
when evaluating (p1 || p2) if p1 is true does the program read p2?
no
how can you change the seed?
use srand(seed)
what header file is srand( ) under?
cstdlib
what is a way in which you can get a different sequnce of random numbers every time using the rand( ) function?
use srand with time(0) as the seed
what header file is time( ) stored under?
ctime
what is the operator for not?
!
what is the operator for and?
&&
what is the operator for or?
||
what does the not (!) operator do?
negates the true to be false and the false to be true
what does the and (&&) operator do?
reads true if and only if all the boolean operands are true
what does the or (||) operator do?
reads true if any of the boolean operands are true
is this correct c++ syntax?
1<= numberOfDaysInAMonth<=31
no, this would produce a logic error. the following is the correct statement
(1<=numberOfDaysInAMonth) && (31 >= numberOfDaysInAMonth)
when evaluating (p1 && p2) if p1 is false does the program read p2?
no
when evaluating (p1 || p2) if p1 is true does the program read p2?
no
a switch statement checks ____ the cases abd executes the statements in the ____ ____
all
matched cases
what is the syntax for a switch statement?
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; }
in switch expressions the variable must always be ____
an integer
when the value in a case statement matches the value of a switch expression the statements starting from that case are executed until
either a break statement or the end of the switch statement is reached
what is the syntax of a conditional expression for an if else statement
boolean expression ? expression1 : expression 2
where ? acts as if and : acts else
what is the only ternary operator in C++ and why is it a ternary operator
the conditional expression formed by ? and :
it is ternary becayse it uses three operands