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
  1. Faster program development.
  2. Portability across different machines.
  3. Cost-effectiveness due to fewer lines of code needed.
  4. Easier error detection and avoidance.

Generations of Programming Languages

  1. 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.
  2. Second Generation Language (2GL):

    • Assembly language using mnemonics.
    • Advantages: Easier to read and modify than 1GL.
    • Disadvantages: Slower execution and still machine-dependent.
  3. Third Generation Language (3GL):

    • High-level languages like BASIC, Pascal, FORTRAN, C.
  4. Fourth Generation Language (4GL):

    • Designed for database access, closer to human language (e.g., SQL, Oracle).
  5. 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:
    1. Assembler: Converts assembly language to machine language.
    2. Interpreter: Translates high-level code into machine code line by line and runs it immediately.
    3. Compiler: Translates the entire source code before execution.
Advantages of Interpreters
  1. Easier error finding.
  2. No lengthy compilation time.
  3. Less storage space needed.
Disadvantages of Interpreters
  1. Slower execution of programs.
  2. Wasted CPU time on repeated translations.

Programming Terms

  1. Source Code: The original program written in a programming language.
  2. Object Code: The machine language equivalent of source code.
  3. Syntax: The rules and structure of a programming language.
  4. Semantics: The meanings associated with language constructs.

Program Implementation Phase

  1. Create the Source Code: Typing the program.
  2. Compiling: Translating source code into object code.
  3. Linking: Combining code to form executable object code.
  4. Executing: Running the program to see results.
  5. 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

  1. Syntax Errors: Mistakes in the language structure, easily identified by compilers.
  2. Logic Errors: Flaws in program logic producing incorrect results without error messages.
  3. Run-Time Errors: Errors occurring during execution due to unexpected events (e.g., division by zero).

Testing and Debugging Techniques

  1. Dry Run: Manual trace of the program using test data.
  2. Debugging: Finding and fixing errors in the code.
  3. Traces: Printouts showing the program's flow step-by-step.
  4. Testing: Using values to verify program correctness.
  5. 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.