C++ Deck 6 Flashcards

1
Q

What type of value does double store?

A

Standard floating-point that holds fractional data.

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

Memory Size: double

A

8 bytes

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

Signed or Unsigned: double

A

Signed / Unsigned: -1.7x10^-308 to +1.7x10^308

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

What type of value does long double hold?

A

Quadruple precision floating-point for fractional numbers. May not be available on all machines.

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

Memory Size: long double

A

16 bytes

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

Signed or Unsigned: long double

A

Same as double, but with more digits after the decimal point (for higher precision)

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

The 4 main Identifier (variable) style conventions.

A
  1. Start names with a letter (not an underscore).
  2. Should be meaningful / self-documenting
  3. Don’t use special characters
  4. Don’t use keywords / reserved words
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a constant variable?

A

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;

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

What is the meaning of the Escape Sequence: \n

A

new line

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

What is the meaning of the Escape Sequence: \t

A

tab

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

What is the meaning of the Escape Sequence: "

A

double quote

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

What is the meaning of the Escape Sequence: '

A

single quote

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

What is the meaning of the Escape Sequence: \

A

backslash

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

What would a c++ line that outputs a precise floating point value rounded to 3 decimal places look like?

A

cout &laquo_space;fixed &laquo_space;setprecision(3);

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

The 4 parts of a loop.

A
  1. Initialization
  2. Condition
  3. Loop Body
  4. Increment/Decrement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is loop initialization?

A

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.

17
Q

What is a loop condition?

A

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.

18
Q

What is the loop body?

A

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.

19
Q

What is the loop increment/decrement?

A

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.

20
Q

The 6 stages of Step-wise Refinement

A
  1. Identifying the Task (what do I need to accomplish?)
  2. Decomposing the Task (How do I do that?)
  3. Implementing the Basic Loop Structure (for, while, do-while – depending on what you need.)
  4. Implementing a Single Step (write one step)
  5. Refining and Extending (Create more subtasks after the first task is working correctly)
  6. Testing and Debugging (error hunting)
21
Q

What is the syntax of a while loop?

A

while (boolean expression)

{

    statement1;

    statement2;

    // ...

    statementN;

}

22
Q

What is the syntax of a do while loop?

A

do

{

    statement1;

    statement2;

    // ...

    statementN;

} while (boolean expression);

23
Q

What is the syntax of a for loop?

A

for (initialCondition; boolean Expression; iterativeStatement)

{

    statement1;

    statement2;

    // ...

    statementN;

}

24
Q

Should you use a break statement in a loop?

A

NO!

25
Q

When is the best situation to use a while loop?

A

When you don’t know how many times you want the loop to run beforehand.

26
Q

Should you use a continue statement in a loop?

A

NO!

27
Q

When is the best situation to use a for loop?

A

When counting and when we know the exactly the number of times the loop would run.

28
Q

When is the best situation to use a do-while loop?

A

When you don’t know how many times you want the loop to run beforehand, but you do want to make sure that the body of the loop executes at least once before checking the condition.