Activity: Programming Concepts & Logic

Programming languages, translators, algorithms, flowcharts, and program design tools

Grade XI • Computer Science ⏱️ ~40 min

Brief Intro — Programming Concepts & Logic

Programming is more than just typing code; it's a process of logical problem-solving that begins with a clear plan. By understanding how different programming languages work and how translators convert them for the computer, you'll gain a deeper appreciation for the software we use every day.

In this activity, you'll explore the generations of languages, master the use of algorithms and flowcharts, and learn the fundamental control structures that form the logic of every program.

Prerequisites
Objectives
Part 1 Programming Languages & Translators

From machine code to natural language, programming languages have evolved to become more human-readable while requiring complex translators to run.

What is a Programming Language?

A programming language is a set of rules that provides a way of telling a computer what operations to perform. It is a notational system for describing computation in both machine-readable and human-readable forms.

Just like English has words, symbols, and grammatical rules, programming languages also have words, symbols, and syntax rules. Each programming language has different syntax rules.

Low-Level Languages

Machine Language (1GL)

Consists of strings of binary numbers (0s and 1s) and is the only language the processor directly understands.

Merits: Fastest execution, efficient memory use, no translation needed

Demerits: Very difficult to program, time-consuming, hard to debug, requires experts

Assembly Language (2GL)

Uses mnemonic codes (symbolic operation codes like 'ADD' for addition) instead of 0s and 1s. Programs are converted to machine code by an assembler.

Merits: Easier than 1GL, faster programming, easier error identification, easier debugging

Demerits: Not directly understood by computer, hardware-dependent, not portable, requires knowledge of mnemonics

High-Level Languages

Procedural-Oriented Language (3GL)

Designed to express logic and procedure. Examples: C, Pascal, FORTRAN, COBOL

Merits: Flexible, portable, programmer focuses on problem not architecture

Demerits: Needs higher processor and larger memory, execution time slower due to translation

Problem-Oriented Language (4GL)

Users specify what output should be without describing data manipulation details. Examples: Visual Basic, C#, PHP, SQL

Merits: Programmer need not think about procedure, programming is much easier

Demerits: Needs higher processor and larger memory, slower execution

Natural Language (5GL)

Still in development stage, uses normal sentences. Programs have artificial intelligence (AI).

Merits: Easy to program, easy to understand, interactive and interesting

Demerits: Slower than previous generations, requires advanced expensive hardware

Language Translators

Translators convert source code to machine code (binary/object code).

Translator Description Example
Assembler Converts assembly language to binary machine code Assembly programs
Interpreter Translates and executes source code line by line Python
Compiler Converts entire source code to binary before execution C, C++
Hybrid Combination: compiles to bytecode, then interprets Java (Bytecode + JVM)
Compiler vs Interpreter
Aspect Compiler Interpreter
Translation Method Translates entire program at once Translates line by line
Execution Creates binary file, then executes Executes directly from source
Error Detection During compilation (all errors reported) Stops at first error encountered
Speed Faster execution after compilation Slower execution
Types of Program Errors

Compile-time errors: Detected during compilation (syntax/semantic)

Run-time errors: Occur during execution, difficult to identify during development

Part 2 Character Encoding in Digital Systems

Computers represent data using different encoding systems, from pure binary to universal character standards that support global communication.

Absolute Binary

Absolute binary is the fundamental Base-2 numbering system used by CPUs. It represents values using only two states: 0 and 1. Each digit's value is determined by its position as a power of 2.

Function: Primary format for performing arithmetic and logical operations

Representation: The decimal value 10 is expressed as 1010₂

Binary Coded Decimal (BCD)

BCD is a specialized encoding method where each individual digit of a decimal number is represented by its own 4-bit binary sequence (a nibble). Unlike absolute binary, BCD treats digits independently.

Function: Used in systems where decimal rounding errors must be avoided, such as electronic displays (calculators and digital clocks) and financial accounting software

Representation: The decimal number 25 is represented in BCD as 0010 0101 (2 and 5), whereas in absolute binary, it would be 11001

ASCII

The American Standard Code for Information Interchange (ASCII) is a character encoding standard for electronic communication. It originally used a 7-bit binary code to represent 128 characters, including the English alphabet (upper and lowercase), numerals 0-9, and punctuation marks.

Function: Served as the standard for data exchange between different software and hardware manufacturers for decades

Constraint: Limited to the Latin alphabet and lacks support for non-English languages

EBCDIC

The Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8-bit character encoding primarily developed by IBM. It was designed for use on IBM mainframe computers and mid-range systems.

Function: Performs the same task as ASCII, but the binary values assigned to characters are different

Example: The character "A" is 1100 0001 in EBCDIC but 0100 0001 in ASCII

Status: Remains in use primarily for legacy support within corporate and banking mainframe environments

Unicode

Unicode is a universal computing standard designed to provide a unique identification number for every character, regardless of the platform, program, or language. It supports over 140,000 characters, encompassing modern and ancient scripts, mathematical symbols, and emojis.

UTF-8: The most prevalent implementation of Unicode. It is variable-width (using 1 to 4 bytes) and is fully backward-compatible with ASCII

Function: Has largely replaced previous encoding standards to ensure global interoperability across the internet and modern operating systems

Technical Summary Table
System Format Size Primary Application
Absolute Binary Base-2 Math Variable CPU Arithmetic
BCD Digit-by-digit 4 bits per digit Financial/Display hardware
ASCII Character Mapping 7 or 8 bits Standard English Text
EBCDIC Character Mapping 8 bits IBM Mainframe Systems
Unicode Universal Mapping 8, 16, or 32 bits Global Software & Web
Task: Encoding Conversion Practice

Convert the decimal number 25 to both BCD and absolute binary, then match each encoding system to its primary application.

BCD conversion: 2 → 0010, 5 → 0101, so 25 → 0010 0101
Absolute binary: 25 = 16 + 8 + 1 = 11001
Check Answer

Encoding Applications: BCD → calculators/digital clocks/financial software; ASCII → English-text data exchange; EBCDIC → IBM mainframes; Unicode → global web/software

Part 3 Control Structures

Control structures are the basic building blocks of logic, allowing programs to follow sequences, make choices, and repeat actions.

Three Basic Control Structures

Any algorithm can be implemented using just these three structures:

1. Sequence

Instructions executed one after another in order. Like reading a recipe or book.

Example: Accept two numbers, add them, display result.

2. Selection

Choosing which path to execute based on criteria. Uses IF/ELSE or switch statements.

Example: If student passed, clap and cheer. Otherwise, say "Better luck next time."

3. Iteration

Looping or repeating operations a specific number of times or until condition occurs.

Example: Print numbers 1 to 10 by incrementing a counter.

Part 4 Program Design Tools

Algorithms, flowcharts, and pseudocode are essential tools for planning and documenting the logic of a program before writing a single line of code.

Algorithm

Step-wise logical instructions written in human-understandable language to solve a problem in finite time. Written in simple English.

Characteristics:

Steps to develop an algorithm:

  1. Understand the problem
  2. Identify expected output
  3. Develop logic to produce output from input
  4. Test algorithm for accuracy with sample input
  5. Repeat steps till desired result is produced
Flowchart

Pictorial representation of step-wise solutions to a problem. Uses different boxes linked by arrows. Helps programmers develop logic and serves as documentation.

Characteristics:

Advantages: Easy to explain logic, provides documentation, helps detect bugs systematically, guides program writing

Disadvantages: Time-consuming to draw, complicated logic hard to represent

Pseudocode

Program Design Language (PDL) providing skeleton for program design. Artificial and informal language to develop algorithms. Outline of program that can be converted to real statements.

Rules for writing pseudocode:

Interactive Simulator: Flowchart Explorer

Click "Step" to trace through an algorithm that finds the largest of three numbers.

Start Read A, B, C A > B? Yes No Max = A Max = B Max > C? Yes No Max = C Print Max Stop
Click Step to begin tracing the algorithm
Part 5 Examples & Practice

Applying logic to simple problems like adding numbers or finding the largest value is the best way to master program design tools.

Example 1: Add Two Numbers

Algorithm:

  1. Start
  2. Accept first number a
  3. Accept second number b
  4. Add a and b, store in SUM
  5. Display value of SUM
  6. Stop

Pseudocode:

START
    READ a, b
    SUM = a + b
    DISPLAY SUM
END
Example 2: Find Largest of Two Numbers

Algorithm:

  1. Start
  2. Read two numbers a and b
  3. Compare a and b
  4. If a is greater than b, print a otherwise print b
  5. Stop

Pseudocode:

START
    READ a, b
    IF a > b THEN
        DISPLAY a
    ELSE
        DISPLAY b
    ENDIF
END
Example 3: Loop to Print 1-10

Algorithm:

  1. Start
  2. Initialize variable count to 1
  3. Display variable count
  4. Increase variable count by 1
  5. Check whether count exceeds 10
  6. If Yes, go to step 6. If No, go to step 3
  7. Stop

Pseudocode:

START
    count = 1
    DO WHILE count <= 10
        DISPLAY count
        count = count + 1
    ENDDO
END
Task 1: Language Generation Identification

Identify the generation of programming language from the description:

"This language uses mnemonics like ADD, SUB, DIV and requires an assembler to convert to machine code."

Hint

Think about which generation uses symbolic codes instead of binary but is still low-level.

✅ Verify: Your answer should be "2GL" or "Assembly Language" or "Second Generation".

🌟 Stretch Goal: Research and list one advantage and one disadvantage of this language generation.

Task 2: Algorithm Development

Write an algorithm to check whether a user-entered number is even or odd.

Hint

Use the modulo operator (%) to check if remainder when divided by 2 is 0.

✅ Verify: Your algorithm should have: Start, Read number, Check condition, Display result, Stop.

🌟 Stretch Goal: Convert your algorithm to pseudocode using IF/THEN/ELSE/ENDIF.

Task 3: Flowchart Symbol Matching

Match the following flowchart symbols to their meanings:

Hint

Remember: Oval for terminals, Rectangle for actions, Diamond for questions, Parallelogram for data.

✅ Verify: Draw a simple flowchart for adding two numbers using correct symbols.

🌟 Stretch Goal: Create a flowchart for finding the largest of three numbers.

Task 4: Control Structure Identification

Identify the control structure used in each scenario:

  1. A program reads 10 student names one after another
  2. A program checks if a student passed and displays appropriate message
  3. A program calculates grade based on marks using if-else ladder
  4. A program prints multiplication table of a number
Hint

Sequence = order, Selection = decision, Iteration = loop/repetition

✅ Verify: Your answers: 1-Sequence, 2-Selection, 3-Selection, 4-Iteration.

🌟 Stretch Goal: Write pseudocode for one of these scenarios using appropriate control structure keywords.

Task 5: Error Type Identification

Classify the following errors as syntax, semantic, or logical:

  1. Missing semicolon in C program
  2. Using + instead of * for multiplication
  3. Dividing by zero in program
  4. Misspelled variable name
Hint

Syntax = grammar rules, Semantic = meaning/usage, Logical = wrong logic/behavior

✅ Verify: Your answers: 1-Syntax, 2-Logical, 3-Run-time/Logical, 4-Syntax.

🌟 Stretch Goal: Explain which of these would be caught during compilation vs during execution.

Ready to test your knowledge?

Take the Assessment →