coding - Practical 7 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Why might a programme never exit on its own?

A

By explicitly specifying the condition of the while loop as true.

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

How can the programme be controlled at run-time?

A

As we learned with if statements, it is possible to insert a conditional statement in place of true.

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

Describe std::string name = “”;

A

We refer to variables that hold text as strings, or more specifically we use the variable type std::string.

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

How can you compare the value of a string?

A

By using the == operator:

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

What does the logical AND operator (&&) allow?

A

It allows you to connect multiple conditional statements such that they can be tested as one big conditional expression.

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

Describe how the logical AND (&&) operator works.

A
  • If both the conditional statements either side of the logical AND (&&) operator are true, the outcome of the entire conditional expression is true and the oscillator is turned on.
  • If either, or both of the statements are false, then the outcome of the entire expression is false and the call to aserveOscillator() is skipped.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can the logical OR (||) operator be used to test?

A

Whether a series of the conditions are true. (e.g. “yes” or “YES”)

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

Describe how the logical OR (||) operator works.

A

If one (or any) of the conditional statements on either side of the logical OR operator (||) are true, the outcome of the entire conditional expression is true and therefore the loop will continue to run.

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

What does the logical NOT operator (!=) do?

A

Inverts the outcome of a conditional expression. For example, printing ‘funds available’ when the variable cash is not 0.

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

Why can’t you be sure on the order in which the AND and OR will be executed?

A

They have the same order of precedence. When chaining together multiple logical operations it is best practice to place them in brackets.

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

What can a switch/case structure often be used in place of?

A

A multi-way selection if…else if structure - creates more readable and efficient flow control.

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

When is a switch/case structure the preferred method?

A

If an if…else if structure tests an integer variable against a number of constant values

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

What does ‘break;’ do in a switch/case?

A

The switch/case structure terminates. If the variable does not match a specified case, this default case is executed.

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