0% found this document useful (0 votes)
4 views3 pages

Unit 2 Computing

Unit 2 covers foundational programming concepts including problem-solving, algorithms, and programming languages. It discusses the importance of logic building, the role of translators like compilers and interpreters, and the structure of programs including data types, variables, and control structures. Additionally, it introduces functions for code reusability and modularity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Unit 2 Computing

Unit 2 covers foundational programming concepts including problem-solving, algorithms, and programming languages. It discusses the importance of logic building, the role of translators like compilers and interpreters, and the structure of programs including data types, variables, and control structures. Additionally, it introduces functions for code reusability and modularity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Here is Unit 2, focusing on the foundational concepts of programming, problem-solving, and

logic building. These concepts are language-agnostic but are typically taught using C, C++, or
Java at the Class 12 level.

Unit 2: Programming Fundamentals & Logic Building

1. Problem Solving and Logic Building

Before writing any code, a programmer must first understand how to solve the problem
logically.

 Algorithm: A finite, step-by-step set of instructions to solve a specific problem.


Algorithms are written in plain English and focus on the logic rather than the syntax of a
specific language.

 Pseudocode: A method of describing an algorithm using a mixture of natural language


and programming-like structures (e.g., IF temperature > 30 THEN print "Hot").

 Flowchart: A visual representation of an algorithm using standard geometric shapes to


denote different types of steps (e.g., ovals for start/stop, parallelograms for
input/output, diamonds for decision-making).

2. Programming Languages and Translators

Computers only understand machine language (binary: 0s and 1s). Translators are needed to
convert human-readable code into machine code.

 High-Level Languages (HLL): Languages closer to human languages (e.g., C++, Java,
Python). They are easier to read, write, and maintain.

 Low-Level Languages: Languages closer to hardware (e.g., Assembly language, Machine


code).

 Compiler: Translates the entire high-level source code into machine code in one go
before execution. It generates an executable file (e.g., .exe).

 Interpreter: Translates and executes the source code line-by-line. If it hits an error,
execution stops immediately.

3. Basic Structure of a Program

Every programming language has a specific set of rules.

 Syntax: The grammatical rules of a programming language. A syntax error occurs when
these rules are broken (e.g., missing a semicolon at the end of a statement).
 Semantics: The meaning or logic behind the code. A semantic error (or logical error)
occurs when the code runs without crashing but produces the wrong output.

 Integrated Development Environment (IDE): Software that provides comprehensive


facilities to programmers, typically including a source code editor, build automation
tools, and a debugger (e.g., Visual Studio Code, Code::Blocks).

4. Data Types, Variables, and Constants

Programs need to store and manipulate data in the computer's memory.

 Variables: Named memory locations whose values can change during program
execution.

 Constants: Named memory locations whose values cannot be altered once defined.

 Data Types: Specifies the type of data a variable can hold. Common primitive types
include:

o Integer (Whole numbers: 5, -10)

o Float/Double (Decimal numbers: 3.14, -0.005)

o Character (Single letters/symbols: 'A', '?')

o Boolean (True or False)

5. Operators and Expressions

Operators are special symbols used to perform operations on variables and values (operands).

 Arithmetic Operators: Used for mathematical calculations (+, -, *, /, % for


modulus/remainder).

 Relational Operators: Used to compare two values (==, !=, <, >, <=, >=). They always
evaluate to a Boolean result (True/False).

 Logical Operators: Used to combine multiple relational expressions (AND, OR, NOT).

6. Control Structures

By default, a program executes sequentially, line by line. Control structures allow the
programmer to change this flow.

 Sequential Flow: The default top-to-bottom execution.

 Selection (Conditional) Flow: Executes a specific block of code based on a condition.

o if statement: Runs code if a condition is true.


o if-else statement: Provides an alternative block of code if the condition is false.

o switch statement: Evaluates a single variable against multiple possible cases.

 Iteration (Looping) Flow: Repeats a block of code as long as a condition is met.

o for loop: Best used when the number of iterations is known beforehand.

o while loop: Best used when the number of iterations is unknown and depends on
a condition changing during execution.

7. Introduction to Functions

As programs grow larger, writing all the code in one block becomes unmanageable.

 What is a Function? A self-contained block of code designed to perform a specific task.


Functions promote code reusability and modularity.

 Built-in Functions: Pre-written functions provided by the programming language's


standard library (e.g., a function to calculate a square root or print text to the screen).

 User-Defined Functions: Custom functions created by the programmer to solve specific


problems within their application.

You might also like