Lecture 2 Flashcards

Top-level Structure of Programs, Data Representation, Variables

1
Q

A C++ program is a collection of?

A

Functions

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

What type of function is always in a C++ program?

A

main() which is always executed first

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

What are the other functions beside main() called and when are they executed?

A

Other functions in the program are
subprograms and are not executed until they
are called

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

What is a statement and what does this end in?

A

An instruction that ends with a semi-colon

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

What is a block?

A

Any section of code which is surrounded by curly brackets is a block

e.g. A block of 4 statements

{
cout «“A fraction: “«5.0/8.0 «endl;
cout «“Big # : “&laquo_space;7000.0*7000.0«endl;
cout «8 + 5 «” is the sum of 8 & 5\n”;
cout &laquo_space;“Hello world”;
}

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

What are the types of information a computer uses?

A

Simple (needs little or no effort to use)
* To hold whole numbers (integers)
* To hold numbers with fractions (float and double)
* To hold individual characters (char)

Complex (needs a little more work to use)
* Strings
* cin and cout

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

What is the difference between char(acter) and string?

A

Char is single characters, string is a lot of characters

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

What does a C++ program normally need to do?

A
  1. Reserving and labelling some space to store
    information
  2. Getting information like int or string into the space you reserved
  3. Doing something (operate on) with the information (int, float, double, char or string)
  4. Displaying results
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is constant?

A

A fixed value represented by something e.g. π

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

What is a variable

A

A value that can change

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

What is a literal?

A

A fixed value that represents itself, e.g. 2 or 7

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

What can you categorise information as?

A
  • constant
  • variable
  • literal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does information of variable, constant and literals get into the computer?

A

We enter values of literals and constants directly into code but for constants we instruct the computer to reserve space for a constant.

We instruct the computer to reserve space for a variable. We have a choice on how we enter
values of variables. We can enter values directly in code or can be set interactively with a user.

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

What are the named areas of memory called?

A

Variables and Constants

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

What is a declaration?

A

When the computer is instructed to
reserve space for information and at the same time tell the computer the name that will be used to refer to that bit of information

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

What happens when a variable is declared?

A

The computer marks the bit of memory reserves so that it allows its contents to change at any time

17
Q

What happens when a constant is declared?

A

The computer effectively locks the memory reserved and prevents the contents being updated.

18
Q

What are the rules to creating a variable?

A

<type> <identifier>:
needs to be assign at some point
</identifier></type>

19
Q

What are the rules to creating a constant?

A

const <type> <identifier> = <value>;</value></identifier></type>

<type>
choose one data type such as int or float
<identifier>
You create a name. It must obey the rules for
identifiers
<value>
You provide the constant value e.g. for Pi value was 3.142
</value></identifier></type>

20
Q

What are the rules to creating a identifier?

A

An identifier must start with a letter or underscore, and the spaces should be replaced with underscores

21
Q

What can’t be identifiers?

A

Reserved words such as if else or return which have meanings in C++, using these will cause an error

22
Q
A