Computer Studies (AKU-CS)
Topic 2 of 4Aga Khan Board

Programming Basics

Introduction to algorithms, pseudocode, and flowcharts for solving biological problems.

What You'll Learn
An algorithm must be unambiguous, finite, and correct — i…Flowchart symbols: oval=start/end, rectangle=process, dia…Three fundamental constructs: sequence (one after another…Variables hold data that can change; constants hold data …

Programming Basics — AKUEB Computer Studies (SSC)


1. What is Programming?


Programming (or coding) is the process of writing a set of instructions for a computer to follow. These instructions are written in a programming language that the computer can understand and execute.


A program is a sequence of instructions that solves a particular problem or performs a specific task.


The problem-solving process:

  1. Understand the problem — what input do you have? What output do you need?
  2. Plan the solution — design your algorithm (steps to solve it)
  3. Write the code — translate the algorithm into a programming language
  4. Test and debug — run the program and fix errors
  5. Maintain — update and improve as needed



2. Algorithms


An algorithm is a step-by-step set of instructions to solve a problem. It must be:

  • Unambiguous — each step is clear with only one interpretation
  • Finite — it must end after a fixed number of steps
  • Correct — it must produce the right output for all valid inputs

Example algorithm — making a cup of chai:

  1. Pour water into kettle
  2. Boil water
  3. Add tea leaves and sugar
  4. Simmer for 2 minutes
  5. Add milk
  6. Strain into cup
  7. Serve



3. Flowcharts


A flowchart is a visual representation of an algorithm. It uses standard symbols:


| Symbol | Shape | Used for |

|---|---|---|

| Terminal | Oval/rounded rectangle | Start / End |

| Process | Rectangle | Calculation or action (e.g., Add A + B) |

| Decision | Diamond | Yes/No question (e.g., Is A > B?) |

| Input/Output | Parallelogram | Input a value / Display a result |

| Arrow | Line with arrow | Flow of control |


Example — flowchart for checking if a number is even:

  1. START
  2. INPUT number
  3. Is number ÷ 2 remainder = 0? (Diamond — Yes/No)
  • YES → OUTPUT "Even" → END
  • NO → OUTPUT "Odd" → END



4. Pseudocode


Pseudocode is a way of writing algorithms in plain, structured English — it is not actual code but it follows a logical structure. Different exam boards have slightly different conventions; AKUEB uses a readable, structured format:


```

BEGIN

INPUT number

IF number MOD 2 = 0 THEN

PRINT "Even"

ELSE

PRINT "Odd"

ENDIF

END

```


Key pseudocode constructs:


Sequence: Instructions run one after another in order.

```

INPUT length

INPUT width

area ← length * width

PRINT area

```


Selection (IF-THEN-ELSE): Executes different instructions based on a condition.

```

IF score >= 50 THEN

PRINT "Pass"

ELSE

PRINT "Fail"

ENDIF

```


Iteration (loops): Repeats instructions.

```

FOR count ← 1 TO 5

PRINT count

NEXT count

```




5. Programming Concepts


Variables: Named storage locations that hold data. The value can change during the program.

  • Example: `score ← 0` declares a variable called score with starting value 0.

Constants: Like variables, but the value NEVER changes during the program.

  • Example: `TAX_RATE ← 0.17` (Pakistan's GST rate — stays fixed in the program)

Data types:

| Type | What it stores | Example |

|---|---|---|

| Integer | Whole numbers | 42, -7, 0 |

| Real/Float | Decimal numbers | 3.14, 9.8 |

| String | Text / characters | "Ahmed", "Karachi" |

| Boolean | True or False only | True, False |


Operators:

  • Arithmetic: +, -, *, / (divide), MOD (remainder), DIV (integer division)
  • Comparison: =, <, >, <=, >=, <> (not equal)
  • Logical: AND, OR, NOT



6. Types of Programming Errors


Syntax error: The code breaks the grammar rules of the language.

  • Example: Forgetting to close a bracket — `PRINT("hello"` — the compiler rejects it.

Logic error: The program runs without crashing but produces wrong results.

  • Example: Writing `area ← length + width` instead of `area ← length * width` — the program runs but gives wrong answers.

Runtime error: The program crashes while running due to an impossible operation.

  • Example: Dividing by zero or trying to open a file that does not exist.



7. Trace Tables


A trace table is used to manually track the values of variables as an algorithm executes — step by step. This helps detect logic errors.


| Step | number | remainder | Output |

|---|---|---|---|

| INPUT 6 | 6 | — | — |

| remainder ← 6 MOD 2 | 6 | 0 | — |

| IF 0 = 0 | 6 | 0 | "Even" |

Key Points to Remember

  • 1An algorithm must be unambiguous, finite, and correct — it is the plan before the code.
  • 2Flowchart symbols: oval=start/end, rectangle=process, diamond=decision, parallelogram=input/output.
  • 3Three fundamental constructs: sequence (one after another), selection (IF-THEN-ELSE), iteration (loops).
  • 4Variables hold data that can change; constants hold data that never changes during execution.
  • 5Four data types to know: integer, real/float, string, boolean.
  • 6Three error types: syntax (grammar rule broken), logic (runs but wrong output), runtime (crashes mid-execution).
  • 7Trace tables track variable values step-by-step — used to find logic errors.

Pakistan Example

Algorithm for a Mobile Top-Up System (Jazz, Telenor, Zong)

Pakistani students interact daily with automated systems that follow algorithms: mobile top-up via SMS (e.g., texting *123*amount# on Jazz). The algorithm: INPUT mobile number and amount → VERIFY number exists in database → CHECK account balance >= amount → IF yes: DEDUCT balance, CREDIT recipient, SEND confirmation SMS → ELSE: SEND 'insufficient balance' message. This maps directly to programming concepts: input/output, variables (balance, amount), selection (IF balance >= amount), and sequence. Students can trace through this algorithm in a trace table using their own phone numbers and top-up amounts.

Quick Revision Infographic

Computer Studies — Quick Revision

Programming Basics

Key Concepts

1An algorithm must be unambiguous, finite, and correct — it is the plan before the code.
2Flowchart symbols: oval=start/end, rectangle=process, diamond=decision, parallelogram=input/output.
3Three fundamental constructs: sequence (one after another), selection (IF-THEN-ELSE), iteration (loops).
4Variables hold data that can change; constants hold data that never changes during execution.
5Four data types to know: integer, real/float, string, boolean.
6Three error types: syntax (grammar rule broken), logic (runs but wrong output), runtime (crashes mid-execution).

Formulas to Know

Flowchart symbols: oval=start/end, rectangle=process, diamond=decision, parallelogram=input/output.
Pakistan Example

Algorithm for a Mobile Top-Up System (Jazz, Telenor, Zong)

Pakistani students interact daily with automated systems that follow algorithms: mobile top-up via SMS (e.g., texting *123*amount# on Jazz). The algorithm: INPUT mobile number and amount → VERIFY number exists in database → CHECK account balance >= amount → IF yes: DEDUCT balance, CREDIT recipient, SEND confirmation SMS → ELSE: SEND 'insufficient balance' message. This maps directly to programming concepts: input/output, variables (balance, amount), selection (IF balance >= amount), and sequence. Students can trace through this algorithm in a trace table using their own phone numbers and top-up amounts.

SeekhoAsaan.com — Free RevisionProgramming Basics Infographic

Test Your Knowledge!

5 questions to test your understanding.

Start Quiz