Chapter 20 Flashcards

"Further Programming"

1
Q

low-level programming

A

programming which gives instructions directly to the computer’s hardware

used for maximum efficiency and speed. an example of low-level is assembly language

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

addressing modes

A

immediate = the value of the operand is used in the instruction (no reference to memory)

direct = the operand is the memory address which holds the value to be used

indirect = the operand is a memory address which holds another memory address where the value to be used is

indexed = the operand contains a value that must be added with the IX, to produce the address where the instruction to be executed is

relative = the operand forms the distance of the value’s instruction (combined with the PC or IX) from the address of the current instruction

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

symbolic and absolute addresses

A

symbolic addresses = contains a symbolic name for the address it represents
absolute addresses = the numeric address of a memory location. restrictive - program cannot be loaded anywhere else in memory

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

imperative programming

A

describes step by step the commands the computer should follow to complete a task in the order it was given
- is an imperative sequence of statements
- use variables which are changed using assignment statements
- use variables, loops, conditional statements
an example of this is python or java

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

object-oriented programming (OOP)

A

organizes code into objects. translates real world into code.
Python and Java are object-oriented.

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

advantage of OOP over imperative

A

produces robust, more reliable code
attributes can only be manipulated using methods from the class, protecting from accidental change.

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

objects

A

an instance of a class

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

create an object (pseudocode)

A

objectName <- NEW className(<param></param>, <param1>, ...)</param1>

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

class

A

a template for objects.

a data structure that is created by the programmer and has its own attributes and methods which operate on the class.

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

declare a class in OOP pseudocode

A
CLASS class
     PRIVATE attribute : DATATYPE
     PUBLIC PROCEDURE NEW(Givenattribute : DATATYPE)
          attribute <- Givenattribute
     ENDPROCEDURE
     PRIVATE attribute1 : DATATYPE
     attribute1 <- value
     PRIVATE FUNCTION GetAttribute1() RETURNS DATATYPE
          RETURN attribute1
     ENDFUNCTION
ENDCLASS

first procedure is to set the attribute, the function is to return the value of the attribute
methods and properties are assumed to public unless otherwise stated.
new and getattribute1 are just names, all of the names here can be changed

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

why are attributes private? are methods public?

A
  • so that only that class has direct access to the variable - everything else needs a method to change/access the data.
  • to ensure attributes can only be accessed by the class’s own methods
  • to enforce encapsulation//to protect them

yes, methods are public, due to the aforementioned reasons.

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

properties/attributes

A

data stored about an object defined in a class

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

methods

A

subroutines in an object operating on the data

the procedures in a class implementing the behaviours that act on the properties/attributes

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

inheritance

A

allows a new class to inherit the properties and methods of an existing class

the child/subclass has access to all the attributes and methods of the parent/base/superclass, along with having their own attributes and methods.

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

inheritance in pseudocode

A

CLASS childClass INHERITS parentClass

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

polymorphism

A

when a method behaves differently for different classes in the hierarchy

17
Q

containment

A

when a class contains other classes
(one class contains another class type)

18
Q

encapsulation

A

putting properties and methods inside a class (to hide sensitive data from users)

19
Q

abstraction

A

hiding the complex programming and only showing what is necessary

20
Q

getters

A

a getter is used to access/return the value of an attribute

21
Q

setters

A

a setter is used to update the value of an attribute/property

22
Q

what does protected mean?

A

a class and subclass can access a variable, but not any other classes, which must use getters or setters

23
Q

instance

A

an occurrence of an object//an instantiation of a class

24
Q

declarative programming

A

programmer describes the desired output and rather than how to do it
… using facts and rules
… using queries to satisfy goals.
Can be logical or functional
Logical - states a program as a set of logical relations
Functional – constructed by applying functions to arguments / uses a mathematical style

examples are SQL and Prolog

25
Q

prolog rules

A

these are more explanatory than mark-scheme founded
goal = finds the data from the written information that fufills your condition
* studies(Student, history).
* variables are capitalized, nothing else
rule = establishes relationships between variables using an if (:-) operator
query = written in the query window to find an answer from the given data (returns true or false). example:
* ? - likes(john, jane).

26
Q

queries

A

goals stated by the user that the language uses to solve a problem

27
Q

prolog rules

A

instantiation:
vegetable(cucumber). #means cucumber is a vegetable,
full stops follow all statements

:- means IF
, means AND

28
Q

exception handling

A

the process of responding to an unexpected event when the program is running so it does not halt unexpectedly

programming errors, user errors, hardware failure, runtime errors

29
Q

why should you include exception handling routines when writing a program? examples of exceptions?

A
  • to trap runtime errors
  • to prevent a program from halting unexpectedly
  • to produce meaningful error messages
  • e.g. (run-time): dividing by zero, end of file, file not found
30
Q

open a file (not random)

A

OPENFILE “fileName” FOR MODE
#modes are read, write, append

31
Q

read from a file (in read mode)

A

READFILE “fileName”, variableName

32
Q

test if there are any more lines in the file:

A

EOF(“fileName”)

33
Q

write data into a file (WRITE or APPEND mode)

A

WRITEFILE “fileName”, data
#data can be a variable, a string (held in quotations), etc.

34
Q

close a file

A

CLOSEFILE “fileName”

35
Q

random file pseudocode commands:

A

OPENFILE “fileName” FOR RANDOM

SEEK “fileName”, address
#moves the file pointer to a given location, address can be a variable

GETRECORD “fileName”, variable
#used to read a record at the file pointer, inserts the record read into the variable

PUTRECORD “fileName”, variable
#writes a record into the file at the file pointer, data in the variable is inserted into the location in the file

EOF(fileName) and CLOSEFILE fileName