CHAPTER 8: FURTHER PROGRAMMING

8.1 PROGRAMMING PARADIGMS

8.1.1 Low-Level Programming

Characteristics:

Addressing Modes:

8.1.2 Imperative (Procedural) Programming

Characteristics:

Examples:

8.1.3 Object-Oriented Programming (OOP)

Key Terms:

Inheritance Example:

<PYTHON>

class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def get_name(self):
return self.name

class Student(Person): # Inherits from Person
def __init__(self, name, age, student_id):
super().__init__(name, age) # Call parent constructor
self.student_id = student_id

8.1.4 Declarative Programming

Characteristics:

Example:


8.2 FILE PROCESSING

8.2.1 File Modes

Mode Purpose
READ Read from file
WRITE Write to file (overwrites)
APPEND Add to end of file
RANDOM Direct access

8.2.2 Serial File Operations

Reading:

<PYTHON>

file = open("data.txt", "r")
while not EOF(file):
line = READFILE(file)
process(line)
CLOSEFILE(file)

Writing:

<PYTHON>

file = open("data.txt", "w")
WRITEFILE(file, "data")
CLOSEFILE(file)

8.2.3 Sequential File Operations

Search:

Add:

Delete:

8.2.4 Random File Operations

Hashing:

<TEXT>

Position = Hash(Key) MOD FileSize

Direct Access:

<PYTHON>

SEEK(file, position)
GETRECORD(file, record)
PUTRECORD(file, record)

8.3 EXCEPTION HANDLING

8.3.1 Exceptions

Definition: Runtime errors that cause program to terminate if not handled.

Common Exceptions:

8.3.2 Handling Exceptions

Try-Except Structure:

<PYTHON>

try:
# Code that might cause error
file = open("data.txt", "r")
data = file.read()
except FileNotFoundError:
print("File not found")
except Exception as e:
print(f"Error: {e}")
finally:
# Always executes
if 'file' in locals():
file.close()

Purpose:


Revision #1
Created 2026-03-16 12:17:28 UTC by Samuel Lee
Updated 2026-03-16 12:17:44 UTC by Samuel Lee