GET 211 - Lecture Material-Ogu-2
GET 211 - Lecture Material-Ogu-2
Computing and
Software
Engineering
(Programming Concepts)
• Enhances Maintainability – Modular code can be modified without affecting the entire program.
• Promotes Reusability – Functions and modules can be reused across different programs.
• C
• Pascal
• Python
• Java
Key Constructs of Structured Programming
Control Structures
1. Sequential Execution
o Statements are executed one after the other in a logical order.
2. Decision Making (Selection)
o if-else, switch-case statements for conditional execution.
3. Loops (Iteration)
o for, while, do-while loops for repetitive tasks.
4. Functions & Procedures
o Encapsulate code into reusable blocks to improve modularity.
Structured Programming Approach Using C
• Symbols: Special characters ({}, • Statements
;, ++). ➢ Assignment: a = 5;
• Keywords: Reserved words (int,
➢ Conditional: if, else.
if, return).
• Identifiers: Names for variables, ➢ Looping: for, while.
constants, functions. • Operator Precedence:
• Data Types: ➢Parentheses ()
o Primitive: int, float, char. ➢Multiplication *, Division /
o Composite: Arrays, ➢Addition +, Subtraction -
structures.
• Operators: Arithmetic (+, -), ➢Relational >, <=
Logical (&&, ||), Relational (<, >=). ➢Logical AND &&, OR ||
C programming: Example
• Example Code: Factorial in C
• Functions: Reusable code blocks.
#include<stdio.h>
• Recursive Functions: Example:
int main() {
int factorial(int n) {
int n, factorial = 1;
if (n == 0) return 1;
printf("Enter a number: ");
return n * factorial(n-1);
scanf("%d", &n); }
for (int i = 1; i <= n; i++) {
factorial *= i;
}
printf("Factorial: %d\n", factorial);
return 0;
}
Object-Oriented Programming
• OOP is a programming paradigm based on the concept of objects, which contain data (attributes)
and methods (functions).
1. Encapsulation – Bundling data and methods within an object to restrict direct access.
2. Abstraction – Hiding complex implementation details and exposing only the necessary parts.
3. Inheritance – Creating new classes from existing ones to promote code reuse.
4. Polymorphism – Allowing objects to be treated as instances of their parent class for flexibility.
Advantages of OOP
Code Reusability – Inheritance reduces code duplication.
Modularity – Objects can be developed independently and integrated later.
Scalability – Large applications are easier to manage.
Security – Encapsulation restricts direct access to sensitive data.
Real-World Applications of OOP
01 02 03 04 05
Web Game Embedded AI & Machine Enterprise
Development Development Systems (e.g., Learning (e.g., Applications
(e.g., Django, (e.g., Unity, Arduino, TensorFlow, (e.g., ERP &
Spring Boot) Unreal Engine) Raspberry Pi) PyTorch) CRM software)
Differences of Terms of OOP
In programming, syntax
Each programming language
refers to the set of rules and
has its own syntax rules.
structure that define how
Writing code incorrectly
code must be written to be
(syntax errors) will prevent it
understood and executed by
from running properly.
a compiler or interpreter.
1. Python Syntax (Simple and Readable)
greet("Alice")
Uses indentation for blocks
No need for semicolons
2. C++ Syntax (Uses Curly Braces & Semicolons)
#include <iostream>
cout << "Hello, " << name << "!" << endl;
int main() {
greet("Alice");
return 0;
class Main {
public static void main(String[] args) {
System.out.println("Hello, Alice!");
}
}
Uses class and main function
System.out.println for output
Common Syntax Elements in Programming
Keywords Reserved words for specific actions def, if, while, return
1. Arrays
o Example (Python):
o print(numbers[0]) # Output: 10
o Example:
2. Graphs (Nodes & Edges): Used in social networks, maps, and recommendation systems.
o Example (Graph Representation using Dictionary):
o graph = {
o 'A': ['B', 'C'],
o 'B': ['A', 'D'],
o 'C': ['A', 'D'],
o 'D': ['B', 'C']
o }
o print(graph['A']) # Output: ['B', 'C']
Comparison of Data Structures