Lecture 1 – Introduction to Programming Paradigms

Programming Paradigms

Learn the fundamentals of Programming Paradigms understand the difference between procedural and object-oriented programming, explore real-world examples, and master the basics of variables, data types, and control structures to build a strong foundation in modern software development.

What is a Programming Paradigm?

A programming paradigm is a style or way of writing programs.
It defines how we think about problems and how we organize our code to solve them.

There are different paradigms, but the two most common are:

  • Procedural Programming
  • Object-Oriented Programming (OOP)

Procedural Programming

In procedural programming, the focus is on functions or procedures step-by-step instructions that tell the computer what to do.

You write code as a sequence of actions:

  1. Get input
  2. Process it
  3. Produce output

The data and the functions that operate on that data are separate.

Example (C++)
#include <iostream>
using namespace std;

int addNumbers(int a, int b) {
    return a + b;
}

int main() {
    int x = 5, y = 10;
    int sum = addNumbers(x, y);
    cout << "Sum is: " << sum << endl;
    return 0;
}

Here, everything is based on functions.
Data (x, y) and logic (addNumbers) are independent.

Drawback:

As projects grow, managing hundreds of functions and variables becomes confusing.
No clear way to connect data and behavior of real-world entities.

Object-Oriented Programming (OOP)

OOP solves this problem by organizing everything around objects which combine data and behavior. Each object represents something real (like a car, student, or account) and knows how to act.

Key Pillars of OOP:

  1. Encapsulation – Bundle data and methods together.
  2. Inheritance – Reuse properties and methods of existing classes.
  3. Polymorphism – Same action behaves differently based on the object type.
  4. Abstraction – Show only the necessary details, hide the rest.

Understanding the C++ Programming Environment: A Step-by-Step Guide

Why OOP? (Advantages)

ProceduralObject-Oriented
Focus on actionsFocus on objects
Data & logic separateData + logic together
Hard to scaleEasy to maintain & extend
Code repetitionCode reuse via inheritance
Example: calculator programExample: banking system, game, website backend

Real-World Example

Imagine you’re designing a Bank System.

Procedural Way:

You’ll create functions:

deposit();
withdraw();
checkBalance();

You’ll also manage variables like accountNumber, balance, name, etc.
All scattered and independent.

OOP Way:

You’ll create a class:

class BankAccount {
public:
    string name;
    double balance;

    void deposit(double amount) {
        balance += amount;
    }
    void withdraw(double amount) {
        balance -= amount;
    }
};

Now, every object (account) can:

  • store its own data
  • perform its own actions
int main() {
    BankAccount acc1;
    acc1.name = "Ali";
    acc1.balance = 1000;
    acc1.deposit(500);
    cout << acc1.name << " has $" << acc1.balance;
}

Data and logic live together → like in real life.

Basic Syntax Recap

Before diving deep into OOP, students must recall fundamental syntax used in both C++ and Java.

Variables:

int age = 20;
float price = 10.5;
string name = "Ali";

Data Types:

TypeDescriptionExample
intWhole numbers10
float/doubleDecimal numbers3.14
charSingle character‘A’
stringSequence of characters“Hello”
boolTrue/Falsetrue

Control Structures:

If-Else:

if (age >= 18) {
    cout << "You are an adult";
} else {
    cout << "You are a minor";
}

Loops:

for (int i = 0; i < 5; i++) {
    cout << i << " ";
}

While:

int n = 1;
while (n <= 3) {
    cout << n << " ";
    n++;
}

Summary of Lecture 1

ConceptMeaningExample
Programming ParadigmWay of thinking/writing codeProcedural vs. OOP
ProceduralFocus on functionsaddNumbers(a,b)
OOPFocus on objectsBankAccount.deposit()
AdvantageReal-world modeling, reusabilityClasses and objects
Syntax RecapData types, variables, loopsint, for, if

Positive Thought for Students:

“Every great programmer was once a beginner who refused to give up. Keep learning, keep experimenting because every line of code you write brings you one step closer to mastery.”

Leave a Reply

Your email address will not be published. Required fields are marked *