Unit 1 - Fundamentals of programming Flashcards

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

What is an algorithm?

A

A sequence of instructions that can be followed to solve a problem.

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

What can relational operators be used for?

A

To compare values within the expression

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

What are the three types of iteration?

A

Indefinite iteration with the condition tested at the start of the loop. (While)

Indefinite iteration with the condition tested at the end of the loop.

Definite iteration where the loop is performed a given number of times. (For loop)

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

What is a subroutine?

A

A set of instructions with a name

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

What is a function?

A

A subroutine that returns one or more values.

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

What are library subroutines?

A

Pre-defined subroutines.

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

Where do parameters appear?

A

In subroutine definitions. They are part of the subroutine definition.

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

Where do arguments appear?

A

In subroutine calls. They may vary from call to call.

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

What is a local variable?

A

It can only be used in that subroutine, they are created once a method is entered and cleared once the method is exited.

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

What is a global variable?

A

it is defined in the main program and can be used in any subroutine called from the main program.

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

What is the scope of variables?

A

The scope of a local variable is the subroutine which it is declared. The variable does not exist outside the subroutine.

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

What are advantages of local variables?

A

The subroutines will be independent of a particular program and can be re-used in different programs.
There is no chance of accidentally changing a variable in the main program that is used in a subroutine or vice versa.
Keep your subroutines self-contained!
Pass as arguments any values that are needed.

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

What is modular programming?

A

Means breaking down a major task into smaller subtasks.

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

What are some advantages of modular programming?

A

Large programs are broken down into subtasks that are easier to program and manage.
Each module can be individually tested
Modules can be re-used several times in a program.
Large programs are much easier to debug and maintain.
Programs are more easily and quickly written.

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

What does a file consist of?

A

A number of records.

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

What is a record?

A

A data structure consisting of a number of fields which can all be of different data types

17
Q

What is a text file?

A

A text file has fields typically separated by commas, and written one line at a time.
You can create, read and manipulate a text file with any text editor.

18
Q

How do you write a file?

A

file=open(‘newFile.txt’,’w’)
file.write()

19
Q

What is a binary file?

A

A binary file can contain records with different types of field such as string, integer, real, Boolean.
Binary files contain bytes.
You can write data to a binary file

20
Q

How do you read a file?

A

file=open(“newFile.txt”, “r”)
file.read()

21
Q

How do you append to a file?

A

file=open(‘newFile.txt’,’a’)

22
Q

Why use a binary file?

A

Text files are convenient because you can read and manipulate them with a text editor, but they can only store a string of characters
Sometimes you need to store a more complex record structure and read it back with the fields intact
A record can store any mix of data types in one unit of data which can be written to a file and read back

23
Q

What is a runtime error?

A

A runtime error will cause a program to crash.

24
Q

Why do you use exception handling?

A

Using exception handling statements, you can intercept and handle exceptions so that your program does not crash.

25
Q

How do you code exception handling?

A

Insert a try… except statement to ensure that it does not crash

26
Q

What are some examples of file handling errors?

A

Trying to open a file which is not in the specified or default folder.
Reading past the end of the file.

27
Q

Why use a constant?

A

Constants reduce the risk of errors by reducing access to the memory location
e.g. pi is 3.14159…

28
Q

How can you change the value of a constant?

A

You have to change it in the source code and then recompile.

29
Q

How can you change the value of a variable?

A

The value of a variable can be changed while the program is running.

30
Q

What can boolean operators be used for (and, or)?

A

To link multiple expressions.

31
Q

What is a case statement?

A

The logical equivalent to the if…then or elif statement.
It can be used to evaluate multiple expressions

32
Q

What does iteration mean?

A

Iteration means repetition

A sequence of instructions is repeated multiple times

This is much more efficient than writing the instructions multiple times

33
Q

What is an infinite loop?

A

You may cause an infinite loop if you make a coding error.

Computer control and data sensing applications use infinite loops to gather data from sensors. After the setup code is run, the device enters an infinite loop to repeatedly check the value of the sensors

34
Q

What is an array?

A

a data structure containing multiple elements all of the same data type, e.g. string, integer, real, etc.