1.2.4 Types of Programming Languages Flashcards

1
Q

What do Procedural programs consist of

A
  • Consist of statements that tell the computer exactly what to do and are executed line by line
  • The basic module of a procedural program is the procedure which is a section of code that performs a task.
  • Functions are also modules but they return a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a paradigm

A
  • To describe an example of a way of doing things
  • Styles of programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do programmers use procedural languages

A
  • Because such languages enable them to focus on the logic problem rather than worrying about high level concepts such as software reuse.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the key features of procedural languages

A
  • Code is run serially, one line after another
  • The language supports selection, iteration and assignment and sequence
  • Code is developed in a modular way - blocks of code identifying set tasks
  • Uses identifiers for variables, constants, prrocedures and functions
  • Variables have either local or global scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Object-Oriented Programming

A
  • Selection, iteration, identifiers for variables and constants are available in OO
  • Procedures are replaced by classes, objects and methods
  • Offers a more modular design, classes allow the developer to produce more reusable code .
  • Captures a group of information data and related functionality into Objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 3 characteristics that define an object-oriented language

A
  • Encapsulation
  • Inheritance
  • Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In OO what are objects and classes

A
  • Object - when you create an instance of a class. Each object that is instantiated from the same class will share the same attributes and methods.
  • Class -A template (1) defining methods and attributes (1) used to make objects (1).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 3 main sections of a class

A
  • Name of the class (light bulb)
  • Attributes - information shared by any object in the class type (variable) (wattage, colour)
  • Methods - code associated with the class, allows access or change to attributes (subroutines) (get Wattage () , get colour()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Inheritance

A
  • When a class takes on the methods and attributes of a parent class.
  • The inheriting class may override some of these methods/attributes and may have additional extra methods and attributes of its own
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Polymorphism

A
  • Something that occurs in several different forms.
  • There are two main types of polymorphism in object-oriented programming - static and dynamic.
  • Polymorphism means that objects of different types can be treated in the same way
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Static Polymorphism

A
  • Allows you to implement multiple methods of the same name but with different parameters (within the same class)
  • This process is known as method overloading
  • The parameter must differ:
    • different number of parameters
    • The types of parameters need to be different (e.g 1 string, 1 integer)
    • Accept the parameters in a different order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Dynamic Polymorphism

A
  • Within an inheritance hierachy, a subclass is able to override a method of its superclass - this allows the code of the subclass to customise or completely replace the behaviour of that method
  • This form of polymorphism - both methods share the same name and parameters, but provide different functionality depending on whether they are implemented by the superclass or subclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you create a class

A
  • Classes in python are defined using the class keyword (class) and indentation.
  • Methods are created using the def keyword.
  • The biggest difference is that all methods must have at least 1 parameter called self and be inside the class indentation block.
  • Self enables functions in Python access to attributes and methods of the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you use attributes and inheritance in python

A
  1. Attributes must be defined in order for them to be part of the class
    * Occurs in the _init_(self) method - called when the class is instatiated. Known in OO terms as a constructor
  2. The base class must be defined first. Put the name of the class in brackets after the name of the subclass. class Scientific (Calculator)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is assembly language

A
  • An assembly language is a low-level programming language for a computer in which there is 1-1 correspondence with the language and machine code instructions
  • Each assembly language is specific to a particular computer architecture
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are some of the mnemonics used in Assembly language

A
  • ADD - add number to the accumulator
  • SUB - subtract a number from the accumulator
  • MUL - multiply a number to the accumulator
  • JMP - jump to memory address and start executing from there
  • Assembly language also uses labels to represent variables and memory addresses. When the program is assembled, these labels are converted into memory address using a symbol table
17
Q

What are the 4 different types of addressing modes

A
  • Immediate addressing mode
  • Direct addressing mode
  • Indirect addressing mode
  • Indexed addressing mode
18
Q

What is immediate addressing mode

A
  • The value in the address part of the instruction is actually the value to be used. Memory doesnt need to be searched to find the required value
  • ADD 10 “means add 10” not value in address 10
19
Q

What is direct addressing mode

A
  • The value in the address part of the instruction is a reference to the address in memory where the required value is located
  • For example ADD 10 means “Go find address location 10, add what you find to the accumulator”.
20
Q

What is Indirect Addressing mode + an advantage

A
  • The value in the address part of the instructon is a reference to a memory location that contains the address in memory where the required value is required
  • Example) ADD 10 means “Go to memory address location 10. There you will find another address. Go to this address and add what you find to the accumulator.
  • This mode of addressing is useful - larger address range can be used to reference data/instruction
21
Q

What is Indexed Addressing Mode

A
  • More efficient to use an index register (IR) instead of repeating instructions
  • The IR is set to 0 - 10+ 0
  • After, IR is incremented 10+ 1
  • An array needs to be stored in contigious memory locations
  • ADD 10 means go find memory address location 10. Plus the value in IR (3). Go to memory address 13 and add the number you find there.
22
Q

Can you use variables in assembly language

A
  • You can use variables in assembly language. No worry about memory addresses
  • Allows you to perform valuations . Uses direect addressing to replace val
23
Q

What are Jumps and Compares

A
  • Both allow flow control within assembly language and provide basic functionality of loops and decision statements and functions as found in higher level languages val = 3, if val=3 then
  • Jump instructions allow control to move to a different part of the program specified by a memory address. There are 2 types: unconditional - always jumps and conditional - uses a compare instruction
24
Q

Why are labels used

A
  • Labels are used to specify the destination of a jump instruction.
  • A jump command needs to have a label in order to exactly know where in the code it must jump to. Labels must be converted to memory addresses in assembly
25
Q

What is calling the Kernel

A
  • In assembly language programming, neccessary to invoke kernel code to perform tasks such as file handling or printing.
  • An invocation of kernel code is known as a system call. Each system call needs values in specific registers then make a software interrupt (32 bit) or issue a syscall (64 bit)
  • The Kernel is responsible for dealing with interrupts, how 32 bit Assembly code communicates to the Kernel (can be slow - perform many memory lookups
  • The syscall method in 64-bit code uses specific registers to speed invocation
26
Q

What is a stack

A
  • When an assembly language program is loaded, a stack that contains information about the command - line options is created.
  • The stack is stored in memory and can be manipulated by registers or by instructions push and pop.
  • When a program loads, the stack will contain any command-line arguement
  • The number of items in a stack is always 1 or more even if there are no arguements (name is added)
27
Q

What is Little Man computer

Consider relationship between assembly language code and the LMC

A
  • Considered a RISC (Reduced Instruction Set Computing)
  • Ecah instruction has a simple opcode and makes use of direct addressing
  • Data is stored and used within programs using variables.
  • LMC uses mailbox to be equivalent to memory
  • FDE not used explicitly. Each version displays PC and ACC
28
Q

What is opcode?

A

Part of the instruction / code

Indicates what to do

29
Q

How are branches used in LMC

A
  • Iteration and selection in procedural languages are implemented in machine code using branches (jumps)
  • In order to implement the condition for a while a loop - need to use 2 branches - 1 loop to start and 1 to break iteration
  • LMC has only 2 conditional branches - branch if value in accumulator is positive or 0.
30
Q

EXAM QUESTION: Explain what is meant by “Encapsulation”

A
  • When an attribute is made private so can’t be directly accessed to or changed from outside the class
  • Public methods are used to read/ amend the attributes value
  • Bundling the data with the methods that operate on it and prevent unauthorised access to values so they can’t be accessed or changed
31
Q

EXAM QUESTION: What are the advantages of Encapsulation

A
  • Reduces the chances of errors/ inconsistencies
  • Ensure objects can only be changed in the way intended and are consistent in the way they should behave
  • Protecting data/ can’t be changed accidentally
32
Q

What is the process of making a new object?

A
  • Instantiation
  • When a new object is created a blank version is generated in memory and reference to is returned.
  • The new keyword is responsible for making a class and allocating memory. Attributes can be made using this reference
33
Q

Exam Question: What is the difference between STA and LDA instruction?

A
  • STA store the value in the accumulator into a given memory location
  • LDA loads the value in a memory location into the accumulator.
34
Q

What are some advantages of using object-oriented techniques?

A
  • Breaking a problem down into objects as different team members can work on different objects.
  • Inheritance means that one class can be coded and that code used as the base for similar objects. This will save the team time
  • Encapsulation means that objects only interact in the way intended and prevents unexpected changed to attributes. This means there are likely to be fewer issues as the team combines their code.
  • Polymorphism means that code can be written that is able to handle different objects in the same way. This reduces the volume of code the team need to produce.
35
Q

Exam Question: Describe three features of an object-oriented language.

A
  • Self-contained object / (instance of a) class / entity / real world object …
    • … contains routines / methods / attributes / data
  • Program split into small units/object…
    • … which are used (by other objects) to build a complex system
  • Uses encapsulation…
    • …to hide data within objects / object only accessed through methods
  • Inheritance…
    • … / superclass / subclass / derived classes