Further Programming
Further Programming
Further Programming
Programming Paradigms
A programming paradigm defines the style or model followed when
programming.
o Low-Level Programming
Machine code (binary – lowest level) or Assembly language
“Low” refers to the small/non-existent amount of abstraction
between the language and machine language
Instructions can be converted to machine code without a
compiler or interpreter
The resulting code runs directly on the specific computer
processor, with a small memory footprint
Programs written in low-level languages tend to be relatively
non-portable – code written for a Windows processor might not
work on a Mac processor
Simple language, but considered challenging to use due to
numerous technical details that the programmer must
remember.
o Imperative (Procedural) Programming
It uses a sequence of statements to determine how to reach a
specific goal. These statements are said to change the
program's state as each one is executed in turn.
Mod
Description
e
It opens a file for reading only. The pointer is placed at the beginning
r
of the file.
It opens a file for writing only. Overwrites file if file exists or creates a
w
new file if it doesn’t
Opens a file for appending. Pointer at the end of the file if it exists or
a
creates a new file if not
Reading a file:
o Read all characters
variable.read()
o Read each line and store it as a list
variable.readlines()
Writing to a file:
o Write a fixed sequence of characters to file
variable.write(“Text”)
o Write a list of strings to file
variable.write[“line1”, “line2”, “line3”]
Using direct access or Random File allows us to read records directly.
‘random’ is misleading since records are still systematically read from and
written to the file.
Pseudocode:
Opening a file using the RANDOM file mode, where once the file has been
opened, we can read and write as many times as we would like in the same
session:
OPENFILE <filename> FOR RANDOM
Move a pointer to the disk address for the record before Reading/writing to a
file can occur:
SEEK <filename>, <address>
Each record is given an ‘address’ at which it is to be written – the record key.
Write a record to the file:
PUTRECORD <filename>, <identifier>
Read a record from a file:
GETRECORD <filename>, <identifier>
Close the file:
CLOSE <filename>
Algorithms for File Processing Operations for Serial and Sequential Files:
Display all records:
Delete a record:
Amend an existing record:
Python:
Delete a record:
Amend an existing record:
Compiler Interpreter