Coding - practical 2 Flashcards

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

Give an example of a variable declaration.

A

int year = 2019;

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

How many parts does a variable declaration involve? Describe them.

A

Usually involves 4 parts:

  • The first part is the data type (e.g. int)
  • The second part is the variable name (e.g. year)
  • The third part is the assignment operator (=, used to give variables a value)
  • The fourth part is the value we wish to assign (e.g. 2019)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can you use after the variable declaration?

A

std::cout to print the value of the variable year.

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

Describe the int data type.

A

Store whole numbers, i.e. 1670, 5, 123985718275

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

Describe the float data type.

A

Store numbers with a decimal part. i.e. 0.76, 440.56

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

Describe the std::string data type.

A

Store strings of characters, i.e. “IAP” , “I Love programming”

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

Describe the bool data type.

A

Stores true or false values only

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

Describe the char data type.

A

Store single characters, i.e. ‘a’, ‘b’, ‘5’

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

When would you use std::cin?

A

When you want to change the values of such variables by user input.

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

How do you get the users input?

A

Use std::cin, followed by the&raquo_space; symbol (note the direction of flow, we want to put data from the input into age). We then specify the variable that we want to write into.

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

What does ‘while (true)’ do?

A

This is a loop and it enables any code that is between the { and } to be repeated. The true part of the while loop makes this section of code repeat forever.

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