Chapter 1: Introduction to Programming and Software Design

Fundamentals of Computers and Programming

  • Computer Function: Computers are designed to perform whatever job their programs (software) instruct them to do.

  • Software Creation: Computer programmers write and create software.

  • Computer Program: A defined set of instructions that a computer follows in order to perform a task.

  • Algorithm: A set of well-defined steps executed to perform a task or solve a problem.

  • Real-World Program Design Requirements:

    • The logical flow of instructions

    • The mathematical procedure

    • The appearance of screens (UI)

Computer Hardware Elements

  • Key Hardware Components:

    • Central Processing Unit (CPU): Interprets and executes program instructions.

    • Main Memory: Temporarily stores program instructions and data at discrete memory addresses (such as 10001000, 10011001, 20002000, and 20012001).

    • Secondary Storage: Provides long-term non-volatile data storage.

    • Input Devices: Feeds data and commands into the system.

    • Output Devices: Presents processed data to the user.


Diagram of computer hardware components and main memory layout

Programming Language Hierarchy and Translation

  • Levels of Programming Languages:

    • High-Level Language: Human-readable programming languages (e.g., C++, C, Java).

    • Low-Level Language: Machine-oriented symbolic languages (e.g., Assembly lang).

    • Machine Language: Direct machine code expressed entirely in binary (00s and 11s).

  • Compiler: A specialized program that translates source code written in a high-level language directly into machine language.

Programming Language Elements

  • Key Words: Reserved words with special, predefined meanings (e.g., if, else, while).

  • Symbols: Programmer-defined names, such as variable names.

  • Operators: Characters that execute operations on data (e.g., +, -, *).

  • Punctuations: Structural characters that form part of the program syntax (e.g., {, }, ;).

  • Syntax: The structural rules governing how valid programs are written (e.g., placing a semicolon at the end of each statement).

Variables and Memory

  • Variable: A symbolic name assigned to a specific memory location to store data.

  • Variable Declaration: The programming statement used to declare a variable prior to use.

  • Declaration Rule in C++: In C++, every variable must be declared before it can be used.

Program Development and Problem-Solving Cycle

  • Problem-Solving and Design Techniques:

    • Divide and Conquer: Breaking complex tasks down into smaller, manageable components.

    • Flow Chart: Graphical diagramming of an algorithm's logical execution steps.

    • Top-Down Design: Deconstructing a high-level system into progressively lower-level details.

  • Problem Analysis, Coding, and Execution Cycle:

    • Problem →\rightarrow Analysis →\rightarrow Algorithm →\rightarrow Coding →\rightarrow Preprocessor →\rightarrow Compiler →\rightarrow Loader →\rightarrow Execution

Types of Program Errors

  • Syntax Errors: Grammar and structural violations of the programming language that prevent compilation.

  • Logical Errors: Flaws in the program logic or algorithm that yield incorrect results without necessarily crashing.

  • Runtime Errors: Errors encountered during program execution that force the application to terminate abnormally.