Programming Flashcards Preview

A-Level Computer Science OCR > Programming > Flashcards

Flashcards in Programming Deck (107)
Loading flashcards...
1
Q

Why is it necessary to have a variety of programming languages?

A
  • different languages suit different jobs

- developers prefer certain languages

2
Q

computer program

A

a series of instructions that are executed one after another.
follow the pattern: INPUT -> PROCESS -> OUTPUT

3
Q

3 programming constructs

A

sequence, selection, iteration

4
Q

Sequence

A

do one statement after another in the correct order

5
Q

Selection

A

do a set of statements based on conditions allow your code to make choices- otherwise known as branching

6
Q

iteration

A

do a set of statements again and again (looping)

7
Q

count controlled loops

A

repeat a set number of statements a fixed number of times

8
Q

condition controlled time

A

repeat a set number of statements until a condition is met

9
Q

Variable

A

a name refer to a particular memory location that is used to store data. The value of the data held in that memory location is not known when the program is written and can change while the program is running

10
Q

constant

A

name used to refer to a fixed value. The value is set when the code is written and cannot change while the program is running

11
Q

procedure

A

a self-contained set of commands that can be called from different parts of the program. returns 0 or many values.

12
Q

function

A

a sub-routine that make take one or more parameters and ALWAYS returns a value

13
Q

uses of functions and procedures

A

breaking a problem into manageable sections

preventing duplicating sections of code when it is needed more than once in a program

14
Q

why is manageable code important

A

easy to read, debug and easy to maintain

15
Q

\

A

integer division

16
Q

AND

A

if both inputs are true the output is true else the output is false

17
Q

OR

A

if both inputs are true or one input is true the the output is true else the output is false

18
Q

NOT

A

reverses the outcome of the expression

19
Q

assignment operator

A

single equals, sets the value on the right equal to the value on the left

20
Q

procedural language

A

programming languages where the user gives step by step instructions of what to do

21
Q

assembly language

A

a low level language represented by mnenomics which represents the machine code. one-to-one relationship with machine code.

22
Q

programming paradigm

A

a way to classify programming languages based on their features.

23
Q

3 programming paradigms

A

`procedural
Object Orientated
Assembly

24
Q

why can assembly code for one processor not work for another processor

A

each type of processor has its own unique instruction set

25
Q

Load instruction

A

LDA

26
Q

store instruction

A

STA

27
Q

input instruction

A

INP

28
Q

Output instruction

A

OUT

29
Q

end instruction

A

HLT

30
Q

data storage instruction

A

DAT

31
Q

add instruction

A

ADD

32
Q

subtract instruction

A

SUB

33
Q

branch always instruction

A

BRA

34
Q

branch if zero or positive instruction

A

BRP

35
Q

branch if zero instruction

A

BRZ

36
Q

procedural language examples

A

Pascal, C, Basic and Python

37
Q

Object Orientated languages examples

A

C++ and Java

38
Q

Object Orientated language

A

coders develop a solution which consists of objects that have been modelled on the real world.

39
Q

Class

A

a template to set out a define what attributes an object of a certain type should have

40
Q

three main class sections:

A

class name
attributes
methods

41
Q

instantiation

A

the process of creating an object from a class template

42
Q

constructor method

A

signified by the key word new, initiated instantiation

43
Q

inheritance

A

when a class takes on the methods and attributes of a parent class. The inheriting class may override or add new methods/attributes.

44
Q

Superclass

A

the original class and its code

45
Q

Subclass

A

the new class which inherited from the superclass

46
Q

Over-riding

A

when the method in the subclass shares the same method as further up in the object tree. the over-ridden method takes precedence and replaces the method further up the object tree

47
Q

Encapsulation

A

the protection of attributes and methods of an object so that they can’t be accessed or altered by other objects. (keyword - private)

48
Q

polymorphism

A

when something appears in multiple forms and the program makes sure the correct meaning of a function is run

49
Q

assembly -> machine relationship

A

one-to-one

50
Q

high level -> machine relationship

A

many-to-one

51
Q

four ways of addressing memory in a computer

A

immediate
direct
indirect
indexed

52
Q

immediate addressing

A

when the value in the operand is the actual value to be used. this means the memory does not need to be searched

53
Q

direct addressing

A

where the operand contains the address of the value to be used.

54
Q

indirect addressing

A

where the operand contains the address which contains the address where the value can be found.
useful because it means that the larger addresses in memory can be used to store

55
Q

indexed addressing

A

The value given is added to the valued stored in the index register to give the memory location.

56
Q

Benefits of assembly code (over high level)

A
  • efficient as the code is more specifc
  • direct control of hardware
  • good if no compilers/interpreters installed
  • good if limited memory
57
Q

Benefits of high level code (over assembly)

A
  • optimisers may make code more efficient
  • intuitive and easier to write
  • can be recompiled for different architechtures
  • less code is written (shorter programs)
58
Q

for loop pseudocode

A

for i=0 to 7
print(“Hello”)
next i

59
Q

while loop pesudocode

A

while condition=
code
endwhile

60
Q

do until loop pseudocode

A

do
code
until
condition

61
Q

MOD

A

gives the remainder of a division

62
Q

DIV

A

integer division (rounds down)

63
Q

if/else Pseudocode

A
if condition then
code
elseif condition then
code
else
code
endif
64
Q

switch/case pseudocode

A
switch condition:
case “A”:
code
case “B”:
code
default:
code
endswitch
65
Q

get the substring

A

stringname.subString(startingPosition, numberOfCharacters)

66
Q

by default how are parameters passed?

A

by value

67
Q

reading from a file

A

myFile = openRead(“sample.txt”)
x = myFile.readLine()
myFile.close()

68
Q

writing to a file

A

myFile = openWrite(“sample.txt”)
myFile.writeLine(“Hello World”)
myFile.close()

69
Q

procedure OO pseudocode

A

public procedure
code
endprocedure

70
Q

Inheritance OO pseudocode

A
class Dog inherits Pet
code
endclass
71
Q

create an instance of a class OO

A

objectName = new className(parameters)

72
Q

Attribute

A

variables contained within and associated to an object

73
Q

Method

A

a subroutine associated with an object

74
Q

Object

A

Instance of a class

75
Q

Characteristics of Procedural

A

instructions, sequences, selections, interaction, procedures and functions

76
Q

Advantages of Using encapsulation

A
  • reduces chance of error
  • consistent changes
  • prevents accidental changes
77
Q

using a two dimensional array

A

[1,3]
the first number is the column the second number is the row this would extract the number in the 1st column and the 3rd row

78
Q

//

A

comment

79
Q

.length()

A

find the length of the variable in front of the dot

80
Q

auto-complete

A

feature of an IDE

can view identifiers and help avoid spelling mistakes/ typos

81
Q

syntax highlighting

A

feature of an IDE

identify features quickly, makes it easier to check code is correct

82
Q

stepping

A

feature of an IDE

run one line at a time and check result

83
Q

breakpoints

A

feature of an IDE

stop the code at a set point to check the value of variables

84
Q

variable watch window

A

feature of an IDE

checks values of variables and how they change during execution

85
Q

error diagnostics

A

feature of an IDE

locate and report errors

86
Q

why would something be passed by reference and not by value

A
  • changes the value in the variable passed
  • passes the address/location
  • the change won’t be lost when the procedure ends
87
Q

write a constructor method

A

PUBLIC PROCEDURE NEW(parameters)
SET ATTRIBUTES
END PROCEDURE
done inside the class your making an instance of

88
Q

create an instance of a class

A

variable = new class(values for attributes)

89
Q

passing by value

A

sends the actual data, if changes are made only the local copy is amended

90
Q

passing by reference

A

send the address/location of the variables, if a change is made the original is also changed.

91
Q

benefits of passing by reference

A
  • existing memory space is used, no extra memory is required

- removes inconsistencies when passing to other procedures

92
Q

benefits of passing by value

A
  • doesn’t change the original variable

- good if you don’t want the original variable by edited

93
Q

decomposition

A

splits problems into sub problems, splits these problems further until each problem can be solved

94
Q

advantages of decomposition

A
  • increase speed of development
  • assign areas to specialatieis
  • re-use modules
95
Q

disadvantages of decomposition

A
  • need to ensure sub programs interact correctly

- can introduce errors

96
Q

advanatages of abstraction

A
  • reduces processing/memory requirements

- increases response speed of programs

97
Q

caching

A

data that has been used is stored in cache in case it is needed again allows for faster access for future use

98
Q

benefits of concurrent processing

A
  • saves time so long as processes are independent
99
Q

drawbacks of concurrent processing

A
  • tricky to test
  • tricky to code
  • won’t neccessarily be twice as fast
  • takes up more memory
100
Q

parallel computing

A

When more than one processor is executing separate instructions at the same time

101
Q

concurrent processing

A

When more than one process is running from a program at once with each process in turn being given a slice of processor time/ running on a separate core

102
Q

Default setting of methods and attributes

A

public

103
Q

calling a method

A

object.method(parameters)

104
Q

calling a superclass method

A

super.methodName(parameters)

for constructor: super.New()

105
Q

Inheritance pseudocode

A

Class dog inherits pet
set attributes
methods
endclass

106
Q

Uses of superclass methods

A
subclass methods override the superclass method to support the greater specialisation defined by the subclass. 
It can be useful to call the superclass version before executing the specialised subclass method.
107
Q

Calling the superclass method from an inherited class

A

public procedure new(parameters for class)
super.new(name)
set attributes
end procedure