CHAPTER 8: FURTHER PROGRAMMING
8.1 PROGRAMMING PARADIGMS
8.1.1 Low-Level Programming
Characteristics:
- Close to machine language
- Direct hardware access
- Instructions converted to machine code without compiler
- Non-portable (specific to processor)
- Small memory footprint
- Examples: Assembly, Machine code
Addressing Modes:
- Immediate: Data is value itself
- Direct: Address contains data
- Indirect: Address at address contains data
- Indexed: Address + index register contents
8.1.2 Imperative (Procedural) Programming
Characteristics:
- Sequence of statements changes state
- Explicit control flow
- Variables modified by assignments
- Based on Von Neumann architecture
Examples:
- C, Pascal, BASIC
- Python (also supports other paradigms)
8.1.3 Object-Oriented Programming (OOP)
Key Terms:
- Object: Instance of a class
- Class: Blueprint for creating objects
- Property/Attribute: Data in object
- Method: Function in object
- Inheritance: Child class inherits from parent
- Polymorphism: Same interface, different behaviour
- Encapsulation: Hiding internal details
- Containment: Object contains other objects
Inheritance Example:
<PYTHON>
8.1.4 Declarative Programming
Characteristics:
- States what needs to be done, not how
- Non-procedural
- Control flow implicit
- Backtracking supported
Example:
- Prolog
- SQL
8.2 FILE PROCESSING
8.2.1 File Modes
8.2.2 Serial File Operations
Reading:
<PYTHON>
Writing:
<PYTHON>
8.2.3 Sequential File Operations
Search:
- Read records sequentially
- Compare key field
- Stop when found or key exceeds target
Add:
- Read from old file
- Write to new file
- Insert new record in correct position
Delete:
- Read from old file
- Write to new file
- Skip record to delete
8.2.4 Random File Operations
Hashing:
<TEXT>
Direct Access:
<PYTHON>
8.3 EXCEPTION HANDLING
8.3.1 Exceptions
Definition: Runtime errors that cause program to terminate if not handled.
Common Exceptions:
- Division by zero
- File not found
- Invalid input
- Memory overflow
8.3.2 Handling Exceptions
Try-Except Structure:
<PYTHON>
Purpose:
- Prevent program crash
- Provide meaningful error messages
- Allow graceful recovery