Introduction to Programming Fundamentals and PDLC Notes

Definition and Role of a Computer

  • Definition of Computer: A computer is a machine that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming.

  • Analog vs. Digital Computers:

    • Analog Computer: A machine that operates using analog inputs such as voltage, temperature, or pressure.

    • Digital Computer: A machine that works with input that can be represented by numbers.

Historical Milestones in Computing

  • Jacquard Machine: An automated loom invention; it featured a device fitted with punch cards to simplify the process of manufacturing textiles.

  • Abacus: A device designed to assist in obtaining results for arithmetic operations.

  • Automata: Three dolls built by the Jacquet-Droz family. These dolls were capable of reading instructions, playing music, drawing, and writing letters.

  • Difference Engine / Analytical Engine: An autoptic mechanical calculator designed by Charles Babbage.

  • ENIAC (Electronic Numerical Integrator and Computer): This represents the first programmable, electronic, general-purpose digital computer.

Computer Programs and Programming

  • Definition of a Program: A program is a set of instructions that follows the grammatical rules of a chosen language. It constitutes an application or software that processes input, manipulates data, and produces an output result.

  • The Recipe Metaphor: A program is comparable to a recipe. It contains a list of "ingredients," known as variables, and a list of "directions," known as statements, which instruct the computer on how to handle the variables.

  • Computer Programming: The comprehensive process of writing, testing, debugging (or troubleshooting), and maintaining the source code of computer programs.

  • Computer Programmer: An individual who writes, tests, and maintains programs or software that tells the computer what tasks to perform.

Programming Languages Overview

  • Technical Definition: A set of words, symbols, and codes—encompassing a vocabulary and a set of syntax (grammatical) rules—that enables a programmer to instruct a computer to perform specific tasks.

  • Language Categories:

    • Low-Level Languages: Languages that are closer to the actual language used by the computer hardware (e.g., Machine Language and Assembly Language).

    • High-Level Languages: Languages closer to human languages, making them easier for humans to use (e.g., Python, C++, Java).

Low-Level Languages: Machine and Assembly

  • Machine Language:

    • Known as the fundamental language of the computer's processor or the elemental language of computers (also called machine code or object code).

    • It consists of binary digits (11 and 00) representing high and low electrical voltages.

    • It is the only language a computer can understand directly and execute without conversion or translation.

    • Advantages: Readily understood by the hardware and ready for immediate execution.

    • Disadvantages: Extremely cryptic, difficult for humans to learn, and produces lengthy code where one instruction corresponds strictly to one machine operation.

  • Assembly Language:

    • Uses mnemonics (keywords and symbols) that correspond to executable instruction streams.

    • It is much like English but is not directly understood by the computer.

    • It requires a program called an Assembler to translate assembly code into machine code.

    • Advantages: Easier to learn than binary machine code.

    • Disadvantages: Still requires translation before execution and results in lengthy code compared to high-level languages.

High-Level Languages

  • Characteristics: Instructions resemble everyday spoken language (e.g., print, if, while). They are machine-independent, meaning they can run on different types of computers and operating systems.

  • Conversion: High-level code must be translated into machine language via a Compiler or an Interpreter.

  • Advantages:

    • Easier to learn and use.

    • Shorter programs; a single high-level instruction can correspond to many machine-level operations.

    • Better program efficiency due to faster development times.

  • Disadvantages: Execution is slower because translation is required.

  • Examples of Languages:

    • BASIC (Beginner's All-purpose Symbolic Instruction Code): Developed in the 1950s for university students; the foundation for Visual Basic. Example: PRINT "Hello world!".

    • Visual Basic: Developed by Microsoft, providing a graphical programming environment and a "paint metaphor" for user interfaces.

    • C++: Developed by Bjarne Stroustrup at Bell Labs; adds object-oriented features to the original C language.

    • Python: An interpreted, object-oriented language with dynamic semantics. Supports structured, object-oriented, and functional programming.

Comparison Table: Language Levels

  • Machine Language:

    • Time to Execute: Fastest (no translation required).

    • Time to Develop: Longest (requires high skill, complex instructions).

  • Assembly Language:

    • Time to Execute: Longer than machine language (requires an assembler).

    • Time to Develop: Less than machine language (mnemonics are easier to remember).

  • High-Level Language:

    • Time to Execute: Longest (requires compiler/interpreter).

    • Time to Develop: Easiest/Shortest (ensures better program development efficiency).

Program Development Life Cycle (PDLC)

  • Overview: An iterative process used in software engineering to manage the development of software programs. It provides an organized plan to break development into manageable phases.

  • The Seven Steps of PDLC:

    1. Planning: Goals and objectives are defined. Resources, risks, budget, and schedule are identified.

    2. Problem Analysis (Defining the Problem): Investigation of causes or failures. Requires identifying what is known (Input) and what is desired (Output) via the Input-Process-Output (IPO) Model.

    3. Designing a Solution (Planning the Solution): Dividing the major program activity into modules. Design tools include Structure Charts, Algorithms, Flowcharts, Pseudocode, and Decision Tables.

    4. Implementation (Coding the Program): Expressing the solution logic in a specific programming language (e.g., Java, Python).

    5. Testing and Debugging: Running the program and executing its functions with sample data. Debugging refers to finding and correcting mistakes.

    6. Deployment: Installation for customers, user acceptance testing, and marketing.

    7. Maintenance: Fixing bugs, adding new features, and performing administrative tasks like backups.

Problem Analysis: IPO Model Examples

  • Scenario 1: Fahrenheit to Celsius Conversion:

    • Input: Fahrenheit temperature (FF).

    • Process: C=(F−32)×59C = (F - 32) \times \frac{5}{9}.

    • Output: Celsius temperature (CC).

  • Scenario 2: Calculating Area of a Triangle:

    • Input: Base (BB), Height (HH).

    • Process: T=12×B×HT = \frac{1}{2} \times B \times H.

    • Output: TT (Area of triangle).

Detailed Design Tools

  • Structure Chart: Also called a Hierarchy chart; shows top-down design where boxes indicate tasks. The top box is the main/control module.

  • Algorithm: A sequence of a finite number of steps arranged in a specific logical order to produce a solution.

  • Pseudocode: Plain English text or annotations used to represent algorithm logic without worrying about language syntax.

  • Flowchart: A diagrammatic representation showing program logic through specific shapes and interconnecting arrows.

  • Decision Table: A special table divided into four parts that specifies actions based on various combinations of input conditions.

Types of Programming Errors

  • Syntax Errors: These occur when code violates the rules of the language (e.g., missing semicolons, incorrect indentation, or missing brackets).

  • Logical Errors: A bug where the program runs but produces incorrect or unintended results due to a mistake in the logic (e.g., using the wrong formula).

  • Runtime Errors: Errors encountered while the code is executing that prevent completion, such as null pointer references or array-out-of-bounds errors.

Programming Paradigms

  • Definition: A fundamental style or approach to computer programming, differing in concepts (objects, functions, variables) and computational steps.

  • Common Paradigms:

    • Imperative / Procedural: Focuses on HOW results are obtained using commands that change a program's state. (Examples: C, PHP, Ruby). Advantage: Low memory utilization. Disadvantage: Difficult to parallelize.

    • Object-Oriented (OOP): Based on "objects" containing data (attributes) and code (methods). Objects are typically instances of classes. (Examples: C++, C#, Java, Python). Advantage: Faster development/productivity. Disadvantage: Large program size.

    • Functional: A subset of declarative programming using functions that behave like mathematical functions. Discourages variable assignment and uses recursion. (Examples: Haskell, Lisp). Advantage: Clean syntax. Disadvantage: High memory requirements.

    • Declarative / Logic: Focuses on WHAT should be accomplished without describing the control flow. Treats programs as theories of formal logic. (Examples: Prolog, Miranda). Advantage: Easy optimization. Disadvantage: Hard to understand for those used to other models.

Language Translators

  • Assembler: Converts assembly language programs into machine code. (Examples: GAS, FAP, COMPASS).

  • Compiler: Translates the entire source program into an object program file before execution. (Examples: C++, C, Java, COBOL).

  • Interpreter: Translates and executes high-level instructions one line at a time. (Examples: Python, PHP, Mathematica, LISP).