Programming notes
Problem Solving and Programming
- Top Down Design (Stepwise Refinement)
- An effective approach to tackle large and complex problems by breaking them into smaller, more manageable sub-problems.
- The solutions to each sub-problem are combined to address the original problem.
- Benefits include:
- Reusability: Sections of the algorithm can be reused in other algorithms.
- Simplicity: Tasks or sub-tasks perform a single function.
- Maintainability: Each task is independent, allowing focused changes when necessary.
Programming Languages
Classification
- Programming languages can be broadly classified into two categories:
- Low-Level Languages: Programming languages closer to machine language that utilize symbols the computer can understand.
- High-Level Languages: Programming languages that resemble human languages and are machine-independent.
Advantages of High-Level Languages
- Faster program development.
- Portability across different machines.
- Cost-effectiveness due to fewer lines of code needed.
- Easier error detection and avoidance.
Generations of Programming Languages
First Generation Language (1GL):
- Machine language made up of binary code (1’s and 0’s).
- Advantages: Fast execution, efficient resource use.
- Disadvantages: Tedious to write and not portable.
Second Generation Language (2GL):
- Assembly language using mnemonics.
- Advantages: Easier to read and modify than 1GL.
- Disadvantages: Slower execution and still machine-dependent.
Third Generation Language (3GL):
- High-level languages like BASIC, Pascal, FORTRAN, C.
Fourth Generation Language (4GL):
- Designed for database access, closer to human language (e.g., SQL, Oracle).
Fifth Generation Language (5GL):
- Uses visual interfaces and aims for computing problem-solving (e.g., PROLOG).
Translators
- Purpose: Translators convert programming instructions into machine language.
- Types of Translators:
- Assembler: Converts assembly language to machine language.
- Interpreter: Translates high-level code into machine code line by line and runs it immediately.
- Compiler: Translates the entire source code before execution.
Advantages of Interpreters
- Easier error finding.
- No lengthy compilation time.
- Less storage space needed.
Disadvantages of Interpreters
- Slower execution of programs.
- Wasted CPU time on repeated translations.
Programming Terms
- Source Code: The original program written in a programming language.
- Object Code: The machine language equivalent of source code.
- Syntax: The rules and structure of a programming language.
- Semantics: The meanings associated with language constructs.
Program Implementation Phase
- Create the Source Code: Typing the program.
- Compiling: Translating source code into object code.
- Linking: Combining code to form executable object code.
- Executing: Running the program to see results.
- Maintenance: Updating the program as needed.
Pascal Program Structure:
- Program Heading: Declares the program’s name and input/output streams.
- Program Block: Contains variable declaration and executable statements.
- Program Terminator: A full stop at the end of the program.
Programming Errors
- Syntax Errors: Mistakes in the language structure, easily identified by compilers.
- Logic Errors: Flaws in program logic producing incorrect results without error messages.
- Run-Time Errors: Errors occurring during execution due to unexpected events (e.g., division by zero).
Testing and Debugging Techniques
- Dry Run: Manual trace of the program using test data.
- Debugging: Finding and fixing errors in the code.
- Traces: Printouts showing the program's flow step-by-step.
- Testing: Using values to verify program correctness.
- Test Data: Values to determine program outputs.
Documentation
- Essential for user support and program maintenance, with two types:
- Internal Documentation: Comments and notes within the source code for clarity.
- External Documentation: User manuals or guides explaining how to use the program.
Internal Documentation Features
- Comments, proper indentation, meaningful variable names.
External Documentation Types
- Technical Documentation: Provides information for IT professionals (system requirements, installation).
- User Documentation: Instructions for end-users in simple language, helping them navigate the program.