Coding - practical 10 Flashcards

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

What do arrays allow us to do?

A

Arrays allow us to group together a number of variables in a single statement.

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

Give an example of an array for 4 note numbers.

A
std::array  notes; 
(instead of)
int note1;
int note2;
int note3;
int note4;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the general form of an array?

A
  1. Variable type (e.g. std::array)
  2. Template initialisation ()
  3. Name of our array (notes;)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe template initialisation.

A

Template initialisation is basically a way to tell the compiler what kind of array we want.

  • The triangle brackets ( < > ) are used to tell the compiler what kind of array you want.
  • Within this is the type (e.g. int) and size (e.g. 4)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is reading and writing achieved by?

A

[ ] the square brackets

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

What is the size function?

A
A class method for the std::array class, and returns the number of elements in the array.
- array.size()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you make a variable const(read only)?

A

To make a variable const (read only) we use the const keyword in front of the variable type. Once a variable has been set as const, its value cannot be changed.

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

What are the two main uses of const?

A

Preventing errors

  • Stops you trying to change values that should stay the same
  • Can make code more readable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How else can you define constant values?

A

with the define keyword

- The general form of a define is: #define SYMBOL value

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

What is an enum?

A

An enum is shorting for enumeration and

allows a series of constant symbols to be defined in a series, whereby each enums value is +1 of the previous value.

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

Give an example of an enum.

A
enum waveTypes {
eSine = 0;
eSquare,
eSaw,
eReverseSaw,
eTri,
eNoise,
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly