Here are the solutions to Question One:
a) The history of computer languages began with machine language (binary code), directly understood by the CPU. This evolved into assembly language, which used mnemonics for instructions. The 1950s saw the rise of high-level languages like FORTRAN and COBOL, making programming more human-readable. Later, languages like C emerged, offering more control and efficiency. The 1980s and beyond introduced object-oriented programming with languages like C++ and Java, focusing on modularity and reusability.
b) In C programming, common types of errors include:
• Syntax errors: These occur when the code violates the grammatical rules of the C language (e.g., missing semicolons, misspelled keywords). The compiler detects these errors.
• Runtime errors: These errors occur during program execution (e.g., division by zero, accessing invalid memory locations). The program might crash or produce incorrect results.
• Logical errors: These errors occur when the program compiles and runs without crashing, but produces incorrect output because of flaws in the program's logic (e.g., using the wrong formula, incorrect loop conditions). These are the hardest to debug.
c) The main programming paradigms are:
• Imperative programming: Focuses on how to achieve a result by explicitly stating the steps or commands to change the program's state (e.g., C, Fortran).
• Object-Oriented Programming (OOP): Organizes software design around data, or objects, rather than functions and logic. It uses concepts like classes, objects, inheritance, and polymorphism (e.g., C++, Java, Python).
• Functional programming: Treats computation as the evaluation of mathematical functions and avoids changing state and mutable data (e.g., Lisp, Haskell).
• Logical programming: Based on formal logic, where programs are expressed as a set of logical relations (e.g., Prolog).
d) Computer languages are broadly classified into:
• Low-level languages: These are close to the hardware.
• Machine language: Binary code (0s and 1s) directly executed by the CPU.
• Assembly language: Uses mnemonics to represent machine instructions, requiring an assembler to translate it into machine code.
• High-level languages: These are more abstract and human-readable, requiring a compiler or interpreter to translate them into machine code. They are further categorized into:
• Procedural languages: Focus on sequences of instructions (e.g., C, Pascal).
• Object-oriented languages: Focus on objects and classes (e.g., C++, Java).
• Scripting languages: Often interpreted, used for automation and web development (e.g., Python, JavaScript).
e) The components that make up a C programming language include:
• Keywords: Reserved words with predefined meanings (e.g., int, float, if, while).
• Identifiers: Names given to variables, functions, arrays, etc. (e.g., myVariable, calculateSum).
• Constants: Fixed values that do not change during program execution (e.g., 10, 3.14, 'A').
• Strings: Sequences of characters enclosed in double quotes (e.g., "Hello World").
• Operators: Symbols that perform operations on operands (e.g., +, -, *, /, =, ==).
• Punctuators: Symbols used for syntax and structure (e.g., ;, {, }, (, )).
f) Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures, and loops, in contrast to using simple unconditional jumps like the goto statement. It emphasizes breaking down a program into smaller, manageable modules or functions.
Languages categorized as structured programming languages include:
• C
• Pascal
• Ada
• Fortran (modern versions)