1.2.4 Types of Programming Language Flashcards
Define and give the benefits of the procedural programming paradigm
Relatively simple to learn for beginners
Applicable to a wide variety of problems.
Uses the programming constructs of sequence, branching, iteration, and recursion.
Uses modular techniques to split large programs into manageable chunks.
Define and give the benefits of the object-oriented programming paradigm
Uses features such as classes (methods and attributes), objects, encapsulation, polymorphism and inheritance
Can abstract details of algorithm away from the user
Code/classes are reusable & programs are simpler to maintain.
Define and give an example of the declarative programming paradigm
Languages such as SQL
Uses statements that describe the problem to be solved, and the language implementation decides the best way of solving it.
Define the assembly/low-level programming paradigm
Languages such as Assembly Language
Uses Mnemonics to represent Opcodes
Mainly hardware oriented - Allows greater control of hardware.
Quicker/more efficient to translate.
Makes more efficient use of the CPU.
List the 11 mnemonics used in LMC
ADD
SUB
STA
LDA
BRA
BRP
BRZ
INP
OUT
HLT
DAT
Write the LMC code to take two inputs and output the biggest of them.
State the four addressing modes
Immediate
Direct
Indirect
Indexed
Describe the immediate addressing mode
LDA 12 – Loads 12 into the accumulator
The operand is the value to be used
Doesn’t look for the value in RAM as the value is in the instruction.
Describe the direct addressing mode
LDA 4 would load the contents of location 4
The operand holds the memory location of the value to be operated on.
Describe the indirect addressing mode
LDA 4 would load the address held in location 4 and then load the value in the address that was found using location 4. (Bounces around…)
Operand is the memory location holding a value representing the memory location to be used
Enables a larger range of addressable locations.
Describe the indexed addressing mode
Index register = 3 + LDA 4 - Would load the data at location 7
Operand is added to the contents of the ‘Index Register’ to get the memory location of the value needed.
Used to access an array whose elements are in successive memory locations.
Describe a class
A template defining methods and attributes, used to make objects.
Describe an object
An instance of a class is called an object and is created using a constructor (new)
Describe a method
The actions that can be performed by an object; for example, get a position on a game board.
Describe an attribute
Each object will have its own public or private attributes.
The attributes of a player in a game of Monopoly might include its PlayerID and money.
Define encapsulation and the benefits of using it.
Attributes are set as private so they can only be accessed and changed via public methods
Uses ‘set methods’ to modify the value of a private attribute
Uses ‘get methods’ to retrieve the value of a private attribute
Prevents unexpected changes to attributes having unforeseen consequences.
Define inheritance
The child class has its attributes and methods, but it also gets all attributes and methods from the parent class.
Uses the keyword ‘Inherits’
Define Polymorphism (overriding)
Code can be written that can handle different objects in the same way, this reduces the amount of code.
Using methods with the same name in a subclass as in a parent class is called overriding, which is a type of polymorphism.
Overriding allows a sub-class to use its method rather than that of the parent.
Write a constructor for a Player class with the attributes shown:
PlayerID, boardPosition, money
All objects have a money value of 2000.
public procedure new(thePlayerID, thePosition)
playerID = thePlayerID
boardPosition = thePosition
money = 2000
endprocedure
Write the line to instantiate an object called “Boot” at position 10 using the Player class with the attributes PlayerID, boardPosition, money
All objects have an unchangeable money value of 2000.
Boot = new Player(“Boot”, 10)