Chapter 3 Conditions Flashcards
What is a good general practice to add to ending braces?
Add a comment to denote what the end brace is used for
What are three common operators found in Boolean algebra and what values do they manipulate?
“And”, “or”, and “not” are used to manipulate the values “true” and “false”.
What are three common operators found in Boolean algebra?
And
Or
Not
Who is Boolean algebra named after?
George Boole, a nineteenth-century English mathematician.
When using the “and” operator, what is required for the compound condition (entire expression) to be true?
Both sides of the “and” operator must be true
Ex.: 3==3 and 4==4 is true
When using the “or” operator, what is required for the compound condition (entire expression) to be true?
At least one side of the “or” operator must be true
Ex.: 3==3 or 3==4 is true
How does the C programming language treat all nonzero and zero values?
All nonzero values are treated as true while all zero values are treated as false.
What character set represents the “and” Boolean operator?
&& (two ampersands)
What library is the “isdigit ()” function a part of?
The library.
What library is the “isdigit ()” function a part of?
What is the “switch (x)” structure used for?
When programmers want to evaluate a user’s response to a specific set of choices.
Ex.: When a user selects an item from a menu.
What are three common operators found in Boolean algebra?
And
Or
Not
Who is Boolean algebra named after?
George Boole, a nineteenth-century English mathematician.
When using the “and” operator, what is required for the compound condition (entire expression) to be true?
Both sides of the “and” operator must be true
Ex.: 3==3 and 4==4 is true
What is the “srand ()” function used for?
The “srand ()” function seeds a variable into the rand () function to dictate the random number generator algorithm.
What is commonly paired with the srand () function to produce a psuedorandom number generator so that numbers are as random as possible?
The “time (NULL)” function.
Ex.: srand (time (NULL))
What character set represents the “and” Boolean operator?
&& (two ampersands)
What character set represents the “or” Boolean operator?
|| (two pipe characters)
What library is the “isdigit ()” function a part of?
The ctype.h library.
What is the “isdigit ()” function used for?
A tool used to validate whether the user entered either digits or non-digit characters.
The “isdigit ()” function returns “true” if its passed-in value evaluates to a digit, and “false (0)” if not.
What is the “switch (x)” structure used for?
When programmers want to evaluate a user’s response to a specific set of choices.
Ex.: When a user selects an item from a menu.
What keyword is used to stop the processing of each “case” statement after the appropriate “case” statement is matched?
break
What function is used to generate a random number and what operator is it commonly paired with?
The “rand ()” function. It is paired with the modulus (%) operator:
(rand () % 10) + 1 This will generate a random number between 0 and 9 and then add 1 so the new range will be 1 and 10.
What is a disadvantage of the “rand ()” function?
The “rand ()” function generates the same sequence of random numbers repeatedly. It cannot generate another random number without the use of the “srand ()” function.
What is the “srand ()” function used for?
The “srand ()” function tells the “rand()” function to produce a different random number every time it is executed.
What is commonly paired with the srand () function to produce a psuedorandom number generator so that numbers are as random as possible?
The “time (NULL)” function.
Ex.: srand (time (NULL))
Conditions are implemented using what type of structure?
“if” structures which contains an expression enclosed within parenthesis