Types of Programming Language Flashcards

(112 cards)

1
Q

what is a paradigm

A

a way of looking / thinking about something
- a standard
- a certain perspective
- a set of ideas

A new paradigm in business could mean a new way of reaching customers and making money

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

what is a programming paradigm

A

a certain approach we might have to programming

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

Which assembly language mnemonic is used to branch if the accumulator is greater than or equal to zero?

A

BRP

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

Which assembly language command will always change the value in the program counter?

A

BRA

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

Which assembly language mnemonic is used to subtract a variable from the accumulator?

A

SUB

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

Which of these is a feature of object orientated programming languages?
Select the most appropriate answer.

Programs are structured into procedures and/or functions

Uses symbolic address as labels to reference locations of data in memory

Commands have a one-to-one relationship with machine code

Programs are structured into classes, methods and instances

A

Programs are structured into classes, methods and instances

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

What keyword should be placed before an attribute or method in pseudocode if we want to make sure it can be accessed by other objects?

A

PUBLIC

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

Which of these is a feature of a low level programming language?
Select the most appropriate answer.

Source code is easier to write

Large number of instructions

Translates to many different machine types

Source code is harder to write

A

Source code is harder to write

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

What does this line of object orientated pseudo-code do?
CLASS teacher INHERITS Person

A

Creates a new subclass called teacher which inherits from the person class

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

Which is the correct definition of ‘direct addressing’?
Select the most appropriate answer.

The operand is an address to a memory location containing an address
The address is the base address plus the value in the index register
The operand is a value to be used by the instruction
The operand is the address to use by the instruction

A

the operand is the address to use by the instruction

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

indexed addressing

A

modifies the address by the addition of a number held in the index register

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

object

A

an instance of class

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

subclass

A

a class that extends another class. the subclass inherits the methods and attributes of the class it extends

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

method

A

a subroutine contained within a class / object designed to perform a particular task on the data within the object

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

superclass

A

a class that has been extended by another class

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

attribute

A

a single item of data within a record or object

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

define low level language (2 marks)

A

a language which is close to machine code

one mnemonic translates to one machine code instruction

a language that is most suited to the machine architecture

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

state three advantages of programs written in Assembly language (3 marks)

A

one to one relationship with machine code

can make use of special machine-dependent instructions
e.g. in the instruction set for the chip

translated program requires less memory

code can execute more quickly

easier to optimise

can work directly on memory locations

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

explain inheritance

A

a class has all the attributes and operations/methods …

…of its superclass…

…and may also have attributes and operations/methods of its own

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

class

A

a class is a type definition

a class has attributes and methods

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

A product manager at ‘Better Solutions Ltd’ oversees a team of developers who program in both high-level and low-level languages.

Justify why the team may sometimes choose to write programs in either a high-level or low-level language. (6 marks)

A

high-level language
- easier to learn / understand code …
- programs can often be developed faster
- programs are prone to less errors / bugs
- programs are easier to debug / maintain / improve
- easier to find programmers who specialise in high-level language
- some high-level languages are specifically designed to solve certain types of problems

low-level language
- code is optimised for a specific architecture
- code can execute extremely fast
- the assembled code occupies less space in the memory than the machine code equivalent produced by a high level complier
- individual statements are able to manipulate / control specific hardware components

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

types of programming paradigms

A

object-oriented programming (OOP)
imperative programming
declarative programming
procedural programming

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

where do all these paradigms come from

A

high level language
assembly language
machine code

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

low-level vs high-level languages diagram

A

HLL OO & visual languages
HLL HL language: C, Fortran, Pascal
LLL assembly language
LLL machine language
LLL hardware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
high level language
uses more human readable statements and constructs each line of code will translate to multiple lines of machine code uses an assembler or complier to translate into machine code much more complex and further abstracted from machine code
26
assembly language
uses short codes called mnemonics e.g. ADD, R1, R2 or INP X for each mnemonic there is one sequence of 1s and 0s they are slightly more abstracted and easier to read / write an assembler is used to translate from assembly language to machine code
27
machine code
we use 1s and 0s to represent the electrical signals within the computer it's the closest to what is happening on the computer which makes it the least abstract
28
types of high level languages
imperative - focus is on describing how a program operates - made up of statements that will change the programs state using sequence, selection and iteration declarative - focuses on WHAT the program should accomplish
29
examples of declarative
logic functional
30
examples of imperative
object oriented procedural
31
imperative high level languages
object oriented - looking at the word as objects which have attributes and methods example: car or plane or person procedural - programs are built from one or more subroutines
32
Procedural VS OOP features
procedural - uses sequences, selection and iteration OOP - uses sequence, selection and iteration BUT also have inheritance, objects, classes and encapsulation
33
Procedural VS OOP data
procedural - data is stored in local or global variables and passed using parameters to other parts of the program OOP - data can be private to each object, stored in attributes which are retrieved and changed through methods. this concept is encapsulation
34
procedural VS OOP program structure
procedural - procedures and functions OOP - classes, methods and instances
35
Procedural VS OOP program logic
Procedural - program flows through calls to procedures and functions OOP - objects are created and the objects methods are called when they are needed. Objects interact with other objects whilst the program is still running
36
why do we need different programming paradigms
different problems need different approaches a 3D game for example will be better suited to OOP as the character, enemies, obstacles, backgrounds etc can be different objects simple quizzes might be suited to procedural languages as OOP would add extra complexity
37
which paradigm for making a mario cart
OOP
38
which paradigm for creating a quiz
procedural
39
what paradigm for designing a website
declarative - HTML
40
what paradigm for querying a database
Declarative - SQL
41
features of procedural programming
program control and flow pre-defined functions - sequence - selection - iteration local variables global variables modularity - procedures - functions passing parameters
42
procedural programming
the language tells the computer what to do by giving step by step instructions features of procedural languages: sequence, selection and iteration code is created in a modular way: Procedure and functions
43
global variables
global variables can be seen in the whole program, every function and procedure
44
local variables
local variables will only be able to be seen in their function on procedure. This is called the SCOPE of the variable
45
passing parameters
sum (a, b) public static int sum (int start, int end) { int s; s = 0; for (int i = start; i <= end; i++) s += i; return s; } a and b are arguments they are passed to parameter variables this is parameter "passing" the parameter variables are int start and int end a is passed into int start b is passed into int end
46
assembly language - low level language
the first languages were machine code languages where the programmers entered binary combinations very difficult to read and write it would be easier to have readable words lead to the development of assembly languages which use mnemonics - simple letter codes like ADD, SUB, LDA there is a one-to-one relationship with the mnemonics and the binary instruction the mnemonics are specific to the machines CPU e.g. Intel, ARM, AMD, Qualcomm etc. They are non portable
47
assembler
used to translate the assembly code into machine code
48
the instructions is broken up into two parts ...
opcode and operand
49
opcode
this is the action to be performed e.g. ADD, LOAD
50
operand
this is the data or address for the opcode to act on e.g. it could be loading data from an address OR it could be data to add
51
advantages of machine code and assembly language
assembly language is quick to execute as each mnemonic maps onto one machine code can access system features without a separate interface, which would add more time very powerful as you are interacting directly with the machine. You're in control without any extra features a high level language might not do smaller programs - require less memory
52
disadvantages of machine code and assembly language
each code is dependant on the machine hard to code and time consuming bug prone as there are no debugging features hard to understand need good understanding of hardware
53
why are assembly languages used for embedded systems
have limited number of tasks size restriction with limited resources e.g. storage and cooling program needs to make efficient use of the processor, storage and power assembly languages can create optimised programs and efficient
54
why are assembly languages used for device drivers
device drivers need to interact with peripherals they need them to perform in a specific way assembly languages allow for precise control of hardware the programs run quickly and are efficient
55
mnemonic > instruction (alternative mnemonics accepted) (there's 11)
ADD > Add SUB > Subtract STA > Store (STO) LDA > Load (LOAD) BRA > Branch always (BR) BRZ > Branch if zero (BZ) BRP > Branch if positive (BP) INP > Input (IN, INPUT) OUT > Output HLT > End program (COB, END) DAT > Data location
56
what are the simple letter codes used in assmebly langauge
mnemonics
57
what converts assembly langauge to machine code?
assembler
58
memory addresses
The CPU accesses addressed locations in main memory. there are different modes locations can be addressed
59
modes of addressing memory
immediate direct indirect indexed
60
immediate addressing
ADD 10 0001 1010 take the following instruction above the 0001 would mean ADD on the instruction set the operand part would actually mean the value NOT address The value here in denary is 8 4 2 1 1 0 1 0 so 8+2 = 10 The actual instruction is ADD 10 The operand specifies a value. This value will be used in the operation
61
direct addressing
ADD 10 0001 1010 take the following instruction above the operand part would actually mean the address of the value to use we know 1010 = 10 as 8 + 2 is 10 we would go to the address in memory and add the value inside it the address 1010 in RAM is 0000 1110 so we add the value In this case it's 128 64 32 16 8 4 2 1 0 0 0 0 1 1 1 0 so 8 + 4 + 2 = 14 the operand specifies the address of a memory location. The contents of this memory location will be used in the operation
62
indirect addressing
ADD 10 0001 1010 take the following instruction above the operand specifies the address of a memory location which holds the address of another memory location. the contents of the second location will be used in the operation we know 1010 is the 10th address in RAM and it is 0000 1110, we know the denary value of that 8 digit code is 14 so we go to address 14 and use the value there address 14 = 1010 1001 128 64 32 16 8 4 2 1 1 0 1 0 1 0 0 1 so 128 + 32 + 8 + 1 = 169
63
indirect addressing - whats the point
it means we can address MORE locations
64
indexed addressing
Combines a base address with an index to compute the effective address If BX contains 0050h and SI has a base address 1000h: MOV AX, [BX + SI] // Move the value at memory location 1050h to AX Fetches data from the effective address (because 1000h + 0050h is 1050h) and moves it into the AX register
65
write psuedocode for the following class Node Attributes Data (string) Methods getData() setData()
Class Node{ private data; public procedure new(string d){ data = d; } public void setData(string newData){ data = newData; } public string getData(){ return data } }
66
instantiate a new object called listItem with the data "Banana"
Class Node{ private data; public procedure new(string d){ data = d; } public void setData(string newData){ data = newData; } public string getData(){ return data } } listItem = new Node(“Banana”)
67
which address mode allows you to access more addresses in memory
Indirect: The operand specifies the address of a memory location which holds the address of another memory location. The contents of the second location will be used in the operation.​
68
Which address mode is used for applying the same instructions over an array?
Indexed: The operand specifies the address of a memory location. The contents of the index register, which is a dedicated register in the CPU, will be added to the address to determine a second address. The contents of the second location will be used in the operation.​
69
what are the two other address modes
Immediate: The operand specifies a value. This value will be used in the operation. Direct: The operand specifies the address of a memory location. The contents of this memory location will be used in the operation.
70
inheritance with badger class
Badger Attributes Name: String Age: Integer isMale: Boolean Colour: String Methods getName() setName() getAge() setAge() getGender() setGender() getColour() setColour() This is a badger class It’s very generic and doesn’t fit We can use Inheritance to reuse the code (the attributes and methods) from the badger class and make a more specific class for either a Honey badger or European badger or American badger. This doesn’t affect the original badger class, just extends from it Both the Honey Badger and European Badger inherit the attributes and methods from the Badger class. They can also add their specific attributes and methods Badger is know as the parent class and the Honey Badger and European Badger is known as the child classes. They can still access the attributes and methods from their parent class If you want a inherited method to do something different to the parent class, you can override it in the child class PARENT CLASS Public string getName(){ Return name } CHILD CLASS Public string getName(){ Return ”I am +” name + “a honey badger” } OR Public string getName(){ Return ”I am +” name + “a European badger” } If I want to use the overridden method you would write: hBadger.getName() If you want to use the super class method you would write: hBadger.super.getName()
71
assembly language defintion
a low level language closely related to but more advanced than machine code. it uses descriptive names and mnemonics for instructions, and is related to the design of the computer
72
attributes definition
data recorded as a variable associated with an object
73
classes definition
a template defining the attributes and methods that can be used to create a type of data known as an object
74
direct addressing definition
the simplest addressing mode in assembly language where the operand stores the memory address of the value to be operated on by the operator
75
encapsulation definition
a method of maintaining data integrity by only allowing class methods to access data in an object's attributes
76
immediate addressing definition
an addressing mode in assembly language where the data in the address field is constant and the operand is the value to be operated on by the operator
77
indexed addressing definition
an addressing mode in assembly language where the address of the operand required is calculated by adding a constant from the index register to the absolute address in the instruction
78
indirect addressing definition
an addressing mode is assembly language where the operand stores the address of the location holding the memory address of the required data
79
inheritance definition
the concept of subclasses inheriting the methods and attributes of its parent class (aka its super class)
80
methods definition
a program subroutine that represents and action an object can perform
81
object-oriented languages definition
programming languages where the code is made of units called objects, which are instances of a class objects have their own attributes and behaviours that can interact with each other
82
objects definition
an instance of a class the behaviour of this data item depends on how its attributes were defined
83
polymorphism definition
objects of different classes can use the same method to perform an action
84
procedural languages definition
a high level language where statements are groups into self-contained blocks known as functions and procedures they have built in data types and data structures
85
programming paradigms definition
a style of computation and programming, chosen according to the problem at hand
86
state the advantages of procedural programming
- can be applied to a wide range of problems - relatively easy to write and interpret
87
state a use of declarative programming
- expert systems / knowledge-based systems - artificial intelligence
88
identify the four main structures used in structured programming
sequence selection iteration recursion
89
how does assembly language differ from machine code
assembly language uses mnemonics rather than binary one line in assembly language is equal to one line in machine code
90
what is the function of the STA mnemonic
storing the value in the Accumulator at the given memory address
91
what is the function of the BRP mnemonic
branches to a given address if the value in the Accumulator is positive it is a conditional branch
92
state the function of the opcode and the operand
the opcode specifies the instruction to be performed and the addressing mode the operand holds a value which is related to the data on which the instruction is to be performed
93
state four addressing mode
immediate addressing direct addressing indirect addressing indexed addressing
94
what is a class
a template for an object that defines the state and behaviour of an object an object is an instance of a class
95
give one disadvantage of object oriented langauges
- requires a different style of thinking which can be difficult for programmers accustomed to other paradigms to pick up - OOP may not be suited to all types of problems - generally unsuitable for smaller problems
96
what is sequence
Sequencing: This means that the computer will run your code in order, one line at a time from the top to the bottom of your program. It will start at line 1, then execute line 2 then line 3 and so on till it reaches the last line of your program.
97
what is selection
Selection: Sometimes you only want some lines of code to be run only if a condition is met, otherwise you want the computer to ignore these lines and jump over them. This is achieved using IF statements. e.g. If a condition is met then lines 4, 5, 6 are executed otherwise the computer jumps to line 7 without even looking at line 4,5 and 6.
98
what is iteration
Iteration: Sometimes you want the computer to execute the same lines of code several times. This is done using a loop. There are three types of loops: For loops, while loops and repeat until loops. That’s handy as it enables you not to have to copy the same lines of code many times.
99
IF (score > 90) AND (score <= 100): PRINT "You grade is A*" this code uses...
selection
100
myAge = 12 PRINT "Next year I will be: " PRINT myAge + 1 PRINT "In two years I will be: " PRINT myAge + 2 PRINT "In three years I will be: " PRINT myAge + 3 this code uses...
sequencing
101
IF (timer <= 0) OR (numberOfLives == 0): PRINT "Game Over" this code uses...
selection
102
firstname = INPUT ("What is your firstname?") lastname = INPUT ("What is your lastname?") PRINT ("Hello " + firstname + " " + lastname + "!") this code uses...
sequencing
103
IF LENGTH( password ) < 8: PRINT ("Your password is not valid!") this code uses...
selection
104
If/else if/else are examples of
selection
105
radius = 5 PI = 3.14 discArea = radius * radius * PI PRINT "Disc Area = " + discArea this code uses...
sequencing
106
colourList = ["red","orange","yellow","green","blue","indigo","violet"] PRINT ("The rainbow colours are: ") FOR colour in colourList: PRINT colour this code uses...
iteration
107
IF goalsIn == goalsOut: PRINT "It's a draw" ELSE IF goalsIn > goalsOut: PRINT "Player 1 wins!" ELSE: PRINT "Player 2 wins!" this code uses
selection
108
WHILE (timer > 0): PRINT "Carry on playing..." timer = timer - 1 this code uses...
iteration
109
PROCEDURE drawSquare(size): FOR side FROM 1 TO 4: forward(size) turnLeft(90) this code uses...
iteration
110
PRINT ("---- 7 Times Table ----") FOR number FROM 1 TO 10: PRINT 7 * number this code uses...
iteration
111
For loops, while loops and repeat until loops are all examples of:
iteration
112
what is recursion
functions are expressed in terms of themselves functions are executed calling themselves, until a certain condition known as a base case (which does not call the function) is met