Introduction to
Computer
Programming
Faisal Rehman
1
Presentation Content
• Computer • Programming and Programming
• Components of Computer languages
• Turing Machine • Syntax and Semantics
• Algorithm • Types of Programming Languages
• Pseudocode • What is Python?
• Flow Chart • Why we need to learn programming
• Computation and Computational Thinking as Engineering Students?
• Software • Why Engineers need Python?
• Program • Application of Programming
• Famous Programmers
2
Computer
• A computer is a digital electronic
machine that can be programmed to
carry out sequences of arithmetic or
logical operations (computation)
automatically.
• Modern computers can perform generic
sets of operations known as programs.
• These programs enable computers to
perform a wide range of tasks.
3
Computer
• A computer system is a "complete"
computer that includes the hardware,
operating system (main software), and
peripheral equipment needed and used
for "full" operation.
• This term may also refer to a group of
computers that are linked and function
together, such as a computer network
or computer cluster.
4
Components of Computer
• Central Processing Unit (CPU): The central processing unit (CPU) is the computer component
that's responsible for interpreting and executing most of the commands from the computer's
other hardware and software.
• A modern CPU is usually small and square, with many short, rounded, metallic connectors
on its underside. (Arithmetic Logic Unit (ALU) and Control Unit (CU))
• Arithmetic logic unit (ALU) is a combinational digital circuit that performs arithmetic and
bitwise operations on integer binary numbers. This is in contrast to a floating-point unit
(FPU), which operates on floating point numbers.
• The control unit (CU) is a component of a computer's central processing unit (CPU) that
directs the operation of the processor.
• A CU typically uses a binary decoder to convert coded instructions into timing and control
signals that direct the operation of the other units (memory, arithmetic logic unit and
input and output devices, etc.).
5
Components of Computer
• CPU
• Register: A processor register is a quickly accessible location available to a computer's processor.
Registers usually consist of a small amount of fast storage.
• 64-bit CPUs and ALUs are those that are based on processor registers, address buses, or data buses of
that size. Same for 32-bit CPU.
• Cache: a cache is a hardware or software component that stores data so that future requests for that
data can be served faster; the data stored in a cache might be the result of an earlier computation or
a copy of data stored elsewhere.
• Clock Speed: The clock rate or clock speed typically refers to the frequency at which the clock
generator of a processor can generate pulses, which are used to synchronize the operations of its
components and is used as an indicator of the processor's speed.
6
Unit of Computer
Memory
• Bit is a single and smallest unit of
memory. Its value is either 0 or 1.
• 8 bits makes 1 byte
• 1KB = 1024 bytes
• 1MB = 1024 KB
• 1GB = 1024 MB
• 1TB = 1024 GB
• 1PB = 1024 TB
7
Components of Computer
• Random Access Memory (RAM) Random-access memory is a form of computer
memory that can be read and changed in any order, typically used to store
working data and machine code.
• Python Memory Management resides in RAM called heap.
• Input/Output Device I/O devices (Peripheral device)
• Storage Device: Hard Disk (HD), SSD, Flash Drive, Storage Tapes
• Keyboard and Mouse
• Monitor
• Speaker
• Projector
• Printer
8
Components of Computer
• Computer Buses
• In computer architecture, a bus (shortened form of the Latin omnibus, and
historically also called data highway or databus) is a communication system that
transfers data between components inside a computer, or between computers. This
expression covers all related hardware components (wire, optical fiber, etc.) and
software, including communication protocols.
• USB port (Short range)
• Ethernet (Long range)
• ROM: Read-only memory (ROM), which stores the BIOS that runs when the computer is
powered on or otherwise begins execution, a process known as Bootstrapping, or
"booting" or "booting up".
9
Components of Computer
• BIOS: Basic Input/Output System, also known as the System BIOS, ROM BIOS, BIOS ROM or PC BIOS) is
firmware used to provide runtime services for operating systems and programs and to perform hardware
initialization during the booting process (power-on startup).
• GPU: A graphics processing unit (GPU) is a specialized electronic circuit designed to rapidly manipulate and alter
memory to accelerate the creation of images in a frame buffer intended for output to a display device.
• A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM)
containing a bitmap that drives a video display. It is a memory buffer containing data representing all the
pixels in a complete video frame.
• In a personal computer, a GPU can be present on a video card or embedded on the motherboard. In certain
CPUs, they are embedded on the CPU die.
• Modern GPUs use most of their transistors to do calculations related to 3D computer graphics. Given that most
of these computations involve matrix and vector operations, engineers and scientists have increasingly studied
the use of GPUs for non-graphical calculations; they are especially suited to other parallel problems.
10
Minimum System Requirements for Engineering
Software
• Preferable is CPU core i7 but core i5 or core i3 will also work. Booting process is slow in
i5 and i3.
• RAM 8GB. 4 GB also works but performance is Slow.
• SSD Disk Drive
• Dell Brand. Tested Personally. They are reliable and perform well during Engineering
Calculations.
• Preferably Intel but new AMD processors are also good.
• Good Battery for Laptop
• You can opt for used laptops, used desktop otherwise use your smart mobile phones.
• Preferably Windows 11 or 10. You can use Mac or even Linux if you are good in it.
11
Turing Machine
• A Turing machine is a mathematical model of computation that defines an abstract
machine that manipulates symbols on a strip of tape according to a table of rules.
• Despite the model's simplicity, given any computer algorithm, a Turing machine is
capable of implementing that algorithm's logic.
• The machine operates on an infinite memory tape divided into discrete "cells".
• The machine positions its "head" over a cell and "reads" or "scans" the symbol there.
• Then, based on the symbol and the machine's own present state in a "finite table“ of
user-specified instructions, the machine first writes a symbol in the cell , then either
moves the tape one cell left or right , then, based on the observed symbol and the
machine's own state in the table, either proceeds to another instruction or halts
computation.
• The Turing machine was invented in 1936 by Alan Turing. 12
Algorithm
• In mathematics and computer science, an algorithm is a finite sequence of
well-defined instructions, typically used to solve a class of specific problems or
to perform a computation.
• Algorithms are used as specifications for performing calculations and data
processing.
• You can write algorithm in natural languages, pseudocode, flowcharts,
programming languages or control tables.
13
Algorithm
• The concept of algorithms has existed since antiquity. Arithmetic algorithms,
such as a division algorithm, were used by ancient Babylonian mathematicians
in 2500 BC
• In about the year 825, al-Khwarizmi wrote an Arabic language treatise on the
Hindu–Arabic numeral system, which was translated into Latin during the 12th
century.
• The manuscript starts with the phrase Dixit Algorizmi ("Thus spoke Al-
Khwarizmi"), where "Algorizmi" was the translator's Latinization of Al-
Khwarizmi's name.
14
Pseudocode
• Pseudocode is a plain language description of the steps in
an algorithm.
• Pseudocode often uses structural conventions of a normal
programming language but is intended for human reading
rather than machine reading.
• There are different styles of writing pseudocode which
matches to a given language. e.g., Fortran style, C Style,
Mathematical Style.
15
Pseudocode
BEGIN
NUMBER num1, num2, sum
OUTPUT "Enter first number:"
INPUT num1
OUTPUT "Enter second number:"
INPUT num2
sum = num1 + num2
OUTPUT sum
END
16
Start
Flow Chart i=0
False
i <= 5 ?
• A flowchart can also be defined as a
diagrammatic representation of an True
algorithm, a step-by-step approach
to solving a task. print (i)
i += 1
End
17
Computation and Computational Thinking (CT)
• Computation is any type of calculation that includes both
arithmetical and non-arithmetical steps and which follows a well-
defined model (e.g. an algorithm).
• Computational thinking allows us to take a complex problem,
understand what the problem is and develop possible solutions.
We can then present these solutions in a way that a computer, a
human, or both, can understand.
18
Steps of CT
• There are four key techniques (cornerstones) to computational
thinking:
1. Decomposition - breaking down a complex problem or system
into smaller, more manageable parts
2. Pattern Recognition – looking for similarities among and
within problems
3. Abstraction – focusing on the important information only,
ignoring irrelevant detail
4. Algorithms - developing a step-by-step solution to the
problem, or the rules to follow to solve the problem
19
App, Software, Package
• It is a collection of instructions that
tell a computer how to work.
• Program: A computer program is a list
of instructions that tell a computer
what to do.
• Software: Software can be a single or
collection of programs.
• Programming: The process, activity,
act of writing code or computer
programs.
20
Programming language
• It is a computer language used in computer programming to
implement algorithms.
• A programming language is a set of commands, instructions, and
other syntax use to create a software program.
• Most programming languages consist of instructions for
computers.
• Programming Language is used to write programs. It has set of
rules and keywords which computer can understand.
21
Syntax and Semantics
The syntax of a computer language is the rules that define the
combinations of symbols that are considered to be correctly structured
statements or expressions in that language.
Semantics is the rigorous mathematical study of the meaning of
programming languages.
Semantics refers to the meaning of a program, or what it does when it
runs. A semantic error is an error in logic that causes a program to
produce incorrect or unexpected output.
22
Syntax and Semantics
• Python does not catch semantic errors automatically.
• Semantic errors are problems with a program that runs without producing
error messages but doesn’t do the right thing.
• To detect semantic errors, you need to use test cases that compare the
actual output with the expected output for a given set of input values.
23
Syntax Errors
• Syntax errors are detected by the interpreter during parsing and will
raise a SyntaxError exception.
• Some examples of syntax errors in Python are:
while True
print(‘Hello world’) # Missing colon
whille True: # Misspelling keyword
‘2’ + 2 # Concatenating different types
24
a + # second object or variable not provided
Example of Semantic Error
• For example, consider this program:
num1 = input('Enter a number:')
num2 = input('Enter another number:')
sum = num1 + num2
print('The sum of', num1, 'and', num2, 'is', sum)
• This program has a semantic error because it performs concatenation instead of addition on
the inputs.
• The inputs are strings, not numbers, so adding them will result in a string like ‘23’ instead of 5.
• To fix this semantic error, we need to convert the inputs to integers before adding them:
num1 = int(input('Enter a number:'))
num2 = int(input('Enter another number:'))
sum = num1 + num2
print('The sum of', num1, 'and', num2, 'is', sum) 25
• This program will produce the correct output for numerical inputs.
Programming Languages wrt Hardware
• 3 types with respect to hardware:
• Machine (in binary) close to hardware (baremetal) x86, x86-64, arm,
• Assembly is close to hardware plus logic of program
• High level language logic of program (fortran, c, c++, python, js, sql, java)
• High level language code is translated into machine binary code using a program called
compiler.
• This process of conversion is called compilation.
• Assembler is used for assembly language.
• Interpreter takes very high-level language code and convert to machine readable code.
• Dynamic language means that a command will execute as you type.
26
Compiled and Interpreted Language
• A compiled language is one that is primarily compiled to machine code which is executed natively
by the CPU on most standard hardware (Intel, AMD, ARM, etc.). C, C++, and Ada are three
examples of this.
• An interpreted language is one that is primarily executed either as source code or bytecode
through a dedicated virtual machine. Python, Ruby, and Java are three examples of this.
• Virtual machine [VM] or interpreter — a piece of software which interprets and executes
instructions from bytecode or source code. Examples include the Java JVM and the Python
interpreter.
• Whenever the Python script compiles, it automatically generates a compiled code called as byte
code. The byte-code is not actually interpreted to machine code, unless there is some exotic
implementation such as PyPy.
• The byte-code is loaded into the Python run-time and interpreted by a virtual machine, which is a
piece of code that reads each instruction in the byte-code and executes whatever operation is
indicated.
27
Types
• Type in the world of programming refers to the data types and the
manipulation that is allowed in a specific programming language.
• It describes the structure of the data and how they are stored in
the memory. Strings, integers, Boolean, and Float are all types.
• In terms of programming languages, we can categorize typing into
Statically typed or dynamic typing.
28
Static Type
• Static Type Language: Static typing means that types are known and checked
for correctness before running your program.
• This is often done by the language's compiler.
• For example, the following Java method would cause a compile-error, before
you run your program:
public void foo() {
int x = 5;
boolean b = x;
}
29
Dynamic Type
• Dynamic Type Language: Dynamic typing means that types are only known as
your program is running.
• For example, the following Python script can be run without problems:
def erroneous():
s = ‘cat’ - 1
print(‘hi!’)
• It will indeed output hi!.
30
Dynamic Type
• But if we call erroneous:
def erroneous():
s = ‘cat’ - 1
erroneous()
print(‘hi!’)
A TypeError will be raised at run-time when erroneous is called.
31
Interactive Programming
• Interactive programming, also known as live coding, refers to any computer
programming language that allows the creator to make changes to the
program while it is already running.
32
Programming Paradigm
• Programming paradigms are a way to classify programming languages based
on their features.
• The term programming paradigm refers to a style of programming.
• Imperative programming is a programming paradigm that uses statements
that change a program’s state. It tells the computer how to accomplish a task
step by step.
• Declarative programming is a programming language paradigm that is based
on logic and focuses more on what a program should accomplish rather than
detailing how that should be accomplished.
33
Programming Paradigm
• Object-Oriented Programming (OOP) is a programming paradigm
based on the concept of "objects", which can contain data and
code.
• Procedural Programming is a way of writing programs that follows
a series of steps or procedures.
• It is based on imperative programming, which means it tells the
computer what to do and how to do it.
• Functional programming is a way of coding that uses pure
functions to create maintainable software.
34
What is Python?
• Python is an interpreted, interactive, object-oriented programming
language.
• It incorporates modules, exceptions, dynamic typing, very high-
level dynamic data types, and classes.
• It supports multiple programming paradigms beyond object-
oriented programming, such as procedural and functional
programming.
• Python combines remarkable power with very clear syntax.
35
What is Python?
• It has interfaces to many system calls and libraries, as well as to various
window systems, and is extensible in C or C++.
• It is also usable as an extension language for applications that need a
programmable interface.
• Finally, Python is portable: it runs on many Unix variants including Linux and
macOS, and on Windows.
• There are probably millions of users, though it’s difficult to obtain an exact
count.
• As per TIOBE Index for March 2023, Python is no. 1 Programming Language.
36
Have any significant projects been done in
Python?
• See https://www.python.org/about/success for a list of projects that use
Python.
• Consulting the proceedings for past Python conferences will reveal
contributions from many different companies and organizations.
• High-profile Python projects include the Mailman mailing list manager and the
Zope application server.
• Several Linux distributions, most notably Red Hat, have written part or all of
their installer and system administration software in Python.
• Companies that use Python internally include Google, Yahoo, and Lucasfilm
Ltd.
37
Why Engineers need Python?
• Python is a very high-level general purpose
interpreted language used in science,
engineering, data science and almost all fields. It
is based on ABC language hence very close to
English language.
1. Very close to English language
2. You can easily read and understand the logic
of code even after many years.
3. You can write and understand program very
quickly after learning few basics.
4. These days, many professors, universities,
institutions and researchers prefer python.
Everybody use it.
5. It's free and opensource. 38
Why Engineers need Python?
6. You can find library and code of your problem/field in Python.
7. It has all necessary tools that an engineer need to perform calculations or
make his own program.
8. Programming and software development in python is very fast.
9. You can run it anywhere. On Windows, Mac, Linux, Cloud, iPhone and
Android.
10. It empowers you to become best professional engineer by apprehending big
ideas and concepts in short amount of time. e.g., doing linear algebra
problems, calculus, and AI just by writing few lines of code.
39
Why Engineers need Python?
11. Many best engineering and Computational Software requires use
of Python.
12. It helps to learn and understand better the Math and Engineering
subjects by providing quick calculation steps and then plot using
jupyter notebook.
13. You can create design sheets in Jupyter Notebook that requires
only change of input and then print the calculation report.
14. You will find many engineering and math packages available or
downloadable.
15. It is useful for research analysis, plotting, and visualization
40
Why we need to learn programming as
Engineering Students?
1. Hand Calculation -> Calculator -> Scientific Calculator -> Python.
2. Computer can solve big matrices even more than size of
1000x1000
3. Sometimes we need to write a specific problem using a particular
algorithm that is not available in existing software.
4. You need to add feature to existing software using its
programming interface.
5. Automation of tasks
6. Plotting, Visualization and Mapping.
41
Application of Programming
• Structural Analysis
• Earthquake Analysis
• Blast Load Analysis
• Dam Break Simulation
• Traffic Simulation
• GIS/RS Mapping
• Hydrology Analysis and Channel Flow
• Building Information Modeling
• Quantity Estimate and Planning
• Automation
• Big Data and AI
42
Programmers who created Engineering Software
Ashraf Habibullah John Walker Frank McKenna You
43
Questions
Like
Comment
Subscribe
Share 44