C++ Deck 6 Flashcards
What type of value does double store?
Standard floating-point that holds fractional data.
Memory Size: double
8 bytes
Signed or Unsigned: double
Signed / Unsigned: -1.7x10^-308 to +1.7x10^308
What type of value does long double hold?
Quadruple precision floating-point for fractional numbers. May not be available on all machines.
Memory Size: long double
16 bytes
Signed or Unsigned: long double
Same as double, but with more digits after the decimal point (for higher precision)
The 4 main Identifier (variable) style conventions.
- Start names with a letter (not an underscore).
- Should be meaningful / self-documenting
- Don’t use special characters
- Don’t use keywords / reserved words
What is a constant variable?
A variable declared to be an immutable value. It cannot be changed at any time after initialization. It MUST be initialized when declared (on the same line).
Uses the keyword “const” followed by the data type and then the variable and initialized assignment value.
Constant variable is usually in all caps.
const double PI = 3.14;
What is the meaning of the Escape Sequence: \n
new line
What is the meaning of the Escape Sequence: \t
tab
What is the meaning of the Escape Sequence: "
double quote
What is the meaning of the Escape Sequence: '
single quote
What is the meaning of the Escape Sequence: \
backslash
What would a c++ line that outputs a precise floating point value rounded to 3 decimal places look like?
cout «_space;fixed «_space;setprecision(3);
The 4 parts of a loop.
- Initialization
- Condition
- Loop Body
- Increment/Decrement
What is loop initialization?
The first step; executed before the loop starts and is typically used to initialize a loop control variable. It sets the initial value for the variable that will be used to control the loop.
What is a loop condition?
The condition evaluated before each iteration of the loop. If the condition is true, the loop body is executed. If false, the loop is terminated and the program continues with the next statement after the loop.
What is the loop body?
The loop body contains the code that is executed repeatedly as long as the condition is true. It can consist of one ore more statements or blocks of code.
What is the loop increment/decrement?
The part of a loop responsible for modifying the loop control variable after each iteration. It helps ensure that the condition will eventually be false, preventing an infinite loop.
The 6 stages of Step-wise Refinement
- Identifying the Task (what do I need to accomplish?)
- Decomposing the Task (How do I do that?)
- Implementing the Basic Loop Structure (for, while, do-while – depending on what you need.)
- Implementing a Single Step (write one step)
- Refining and Extending (Create more subtasks after the first task is working correctly)
- Testing and Debugging (error hunting)
What is the syntax of a while loop?
while (boolean expression)
{
statement1; statement2; // ... statementN;
}
What is the syntax of a do while loop?
do
{
statement1; statement2; // ... statementN;
} while (boolean expression);
What is the syntax of a for loop?
for (initialCondition; boolean Expression; iterativeStatement)
{
statement1; statement2; // ... statementN;
}
Should you use a break statement in a loop?
NO!