SlideShare a Scribd company logo
Nadim Ahmed
Introduction to
Programming
01 – Programming and Algorithms
Nadim Ahmed
Nadim Ahmed
Introduction
• You must bring a pen and some paper
with you to write notes from the board.
• This is a challenging subject, so do come
to all lectures and labs, and make plenty
of notes.
• If you have any questions, then please
ask.
Nadim Ahmed
How to Learn
• I will give you exercises to do, so please
do them.
• You will NEVERNEVERNEVERNEVER learn programming by
memorising!
• Make sure you understandunderstandunderstandunderstand what is
happening.
• You must attempt the exercises by
yourself.
Nadim Ahmed
What is a Computer?
“They don’t get angry, they don’t get
happy, they don’t get sad, they don’t
laugh at your jokes. They just run
programs.”
Paraphrased from “Short Circuit”
Nadim Ahmed
What is a Computer?
• Let us start at the beginning and see
what is a computer.
• A computer is a machine that can
calculate and use logic to carry out
tasks.
Nadim Ahmed
What is a Computer
• Computers take in inputinputinputinput.
– This is data that is given to the computer.
• They processprocessprocessprocess the input.
– This is when they manipulate/use the data.
• They produce an outputoutputoutputoutput.
– This is the result of manipulating the input.
Nadim Ahmed
What is Programming?
• To get a computer to carry out different
tasks, we have to be able to give it
specific instructions.
• This is programming.
• Before we start programming, we have
to look at something else.
Nadim Ahmed
Algorithms
• Before writing a program, the
programmer must understand what the
result should be and how the program
will produce it.
• It is important to know that a computer
program describes a computational
procedure called an algorithm.
Nadim Ahmed
Algorithms
• An algorithm is a step by step sequence
of instructions that describes how to
perform a computation.
• An algorithm answers the question
– “What method will you use to solve this
computational problem?”
Nadim Ahmed
Algorithms
• Only after
– we clearly understand the desired result,
– we clearly understand the algorithm and
– know the specific steps required to produce
the desired result
• we can write the program.
Nadim Ahmed
Programming
Programming is the translation of
the selected algorithm into a
language that the computer can
use.
Nadim Ahmed
Programming
Let’s see a real life example of what is
programming.
Nadim Ahmed
Programming a Sponge Cake
• Switch oven on at 180°C
• Cream together 225g softened butter
and 225g of sugar
• Whisk 4 eggs and add to mixture slowly
• Add 225g of sifted self raising flour and
fold.
• Grease two cake tins and add mixture.
• Bake for 20 – 30 minutes until golden
brown.
Nadim Ahmed
Programmable Computer
• Can provide a computer a sequence of
instructions describing the process I
want it to execute.
• Have a fixed set of primitives, can
program almost anything.
– In our sponge cake, the primitives are
commands like
•Cream, whisk, fold, grease.
Nadim Ahmed
Programming and Algorithms
• To illustrate an algorithm, we will
consider a simple requirement.
• Assume that a program must calculate
the average of three numbers.
• Most people do not think
algorithmically;
– They tend to think intuitively.
Nadim Ahmed
Programming and Algorithms
• If your car tyre needs changing,
– you will not think of all the steps required,
– you will either simply change the tyre or
– call someone else to do the job.
• This is an example of intuitive thinking.
Nadim Ahmed
Programming and Algorithms
• Unfortunately, computers do not
respond to intuitive commands.
• A general statement such as “find
average of three numbers” means
nothing to a computer.
– This is because computers can only respond
to algorithmic commands written in an
acceptable language such as C.
Nadim Ahmed
Programming and Algorithms
• To program a computer successfully, you
must clearly understand the difference
between algorithmic and intuitive
commands.
• You must give the computer a detailed,
step-by-step set of instructions that
forms an algorithm.
Nadim Ahmed
Average of Three Numbers
• We have to understand what the
requirements are, and what the result
will be.
• To make it easier, let us identify the
three numbers to use as an example.
Nadim Ahmed
Average of Three Numbers
• We have chosen the numbers
• 2, 3 and 10
Class Discussion:Class Discussion:Class Discussion:Class Discussion:
What do we mean by “find the average of
2, 3 and 10”?
Nadim Ahmed
Average of Three Numbers
• To find the average, we add up 2, 3 and
10.
• Then we divide that by three.
• 2 + 3 + 10 = 15
• 15 ÷ 3 = 5
• Therefore the average is 5.
Nadim Ahmed
Average of Three Numbers
• We now know how to find the average of
three specific numbers.
• How are we going to make it a bit more
general?
• Think of what steps you will take to get
the average of three numbers.
Nadim Ahmed
Average of Three Numbers
Class Discussion:Class Discussion:Class Discussion:Class Discussion:
What do we need to make a generic
program to find the average of three
numbers?
Nadim Ahmed
Average of Three Numbers
• We need to get our three numbers.
• We need to add the three numbers
• We need to divide the total by 3.
Nadim Ahmed
Code Modularity
• When programming, we break our large
problem into modules
– where each module can be thought of as a
single task.
• These modules make it easier to break
down programming problems.
Nadim Ahmed
Making Pizza
When making pizza, we have four basic tasks.
• Make pizza base.
• Make pizza topping.
• Assemble topping on the base.
• Bake pizza in oven.
Each of these tasks can be thought of as a
modulemodulemodulemodule, as they perform one task each.
Nadim Ahmed
Why Modules?
• Programs that use modules are known as
modular programsmodular programsmodular programsmodular programs.
• Modular programs are easier to develop,
correct and modify.
– Since they split the tasks into separate
modules, you can deal with each module
individually.
– If you have a mistake in one module, you
don’t worry about it affecting other modules.
Nadim Ahmed
Modules
• Each module is actually a small
subprogram.
• We break our module into smaller tasks.
• Each module
– InputInputInputInputs some data.
– ProcessProcessProcessProcesses the data.
– OutputOutputOutputOutputs the processed data.
Nadim Ahmed
A Pizza Module
• For our pizza making program, let’s see
our module “Make pizza topping”.
• Let’s say the topping will be a “cheese
and tomato” topping.
• What will the input, process and output
of the module be?
Nadim Ahmed
Make Pizza Topping
• Input
– Cheese
– Tomato
– Garlic
– Green Peppers
– Basil
– Onion
Nadim Ahmed
Make Pizza Topping
• Process
– Gently heat up tomato, garlic, green
peppers, basil and onion.
– Blend the mixture
– Grate the cheese and keep aside.
• Output
– Tomato sauce
– Grated cheese
Nadim Ahmed
Add Module
Class DiscussionClass DiscussionClass DiscussionClass Discussion
• If we have a module that adds two
numbers.
• What are the
– Inputs?
– Processes?
– Outputs?
Nadim Ahmed
Add Module
• Inputs
– Our two numbers that we want to add.
– Let’s call them a and b
• Process
– Add the two numbers and keep the result
safe.
c = a + b
• Output
– The result which is stored in c
Nadim Ahmed
Modules
Class DiscussionClass DiscussionClass DiscussionClass Discussion
• We have a program that can convert between
different types of distances.
• These can be
– kilometres to miles,
– miles to kilometres,
– inches to centimetres,
– centimetres to inches.
• If we have a program that converts different
types of distances then we should break it
down into modules.
– What modules do we use?
Nadim Ahmed
Programming and Modules
• We can have one module that converts
from kilometres to miles, and another
one to convert from miles to kilometres.
• Also, we can have one module that
converts from centimetres to inches and
vice versa.
• In other words, one module for each
task.
Nadim Ahmed
How Will We Program the
Computer?
• We will now look at how we will
program the computer.
• We need to communicate with the
computer so then we are understood by
the computer.
• I am speaking to you in English, which
some of you understand.
• We will now explore languages that
humans can use with computers.
Nadim Ahmed
Levels of Languages
• Computers work in binary
– 0, 1
– Not very human readable.
• To make things easier, we have various
levels of languages.
• These levels range from
– HighHighHighHigh to
– LowLowLowLow
Nadim Ahmed
Levels of Languages
• Machine code is the lowest level of
programming language.
– This is the language that the CPU uses.
– Tailored for each individual CPU.
– If you write something for an ARM
processor, it will not work on an Intel
processor.
Nadim Ahmed
Multiplying in Low Level
• This is an example of multiplying two
numbers in a low level language.
• It has been written for the Zilog Z80
microprocessor, which was very popular
in the late 1970s until late 1980s.
• There was no multiply command, so we
had to add numbers several times.
Nadim Ahmed
Multiplying Two Numbers
org &4000 ; store in memory location 4000
ld b,3 ; load register b with 3
ld a,0 ; load register a with 0
; The following line is in memory location 4004
add a,2 ; add 2 to register a
dec b ; decrement register b by 1.
jp nz,&4004 ; jump if not zero to memory location 4004
ld (&400f),a ; Copy content of register a to location 400f
end ; End of program
Nadim Ahmed
Machine Code
Nadim Ahmed
Memory Before Running
Nadim Ahmed
Memory After Running
Nadim Ahmed
High Level Languages
• In order to make programming easier,
we use a high level language.
• When we use a high level language, we
need to convert it to machine code.
– This is called compilingcompilingcompilingcompiling.
– We use a compilercompilercompilercompiler to compile the sourcesourcesourcesource
codecodecodecode into machine code.
– Source code is our original high level code.
Nadim Ahmed
Multiplying in High Level
• You saw just how much effort was
required to multiply 3 by 2 in low level.
• In a high level language, we can just do
the following:
3*2
Nadim Ahmed
Syntax
• Syntax deals with the grammar of the
language.
– So, if you are speaking English, and say:
Cat ball hit.
– You have a syntax error.
•The cat hit the ball.
• The compiler will tell you about syntax
errors.
Nadim Ahmed
Semantic
• However, if your grammar is correct, but
the meaning is wrong, then you have a
semantic error.
The cat cooked some dolma.
• The grammar is correct, but I very much
doubt that a cat can actually cook dolma.
Nadim Ahmed
Semantic
• Let’s say you wrote down that the area
of a triangle is worked out by the
following equation:
length of base * height of triangle
• You have a semantic error.
• The compiler will not tell you that you
have a mistake in the equation.
Nadim Ahmed
C
• We will be using C as our high level
programming language.
• I have chosen ANSI C as it is a well
known standard that can be used by
most C compilers for different operating
systems.
• It is used widely by programmers and
academics in systems and graphics
programming.
Nadim Ahmed
In Summary
• We have seen
– What is a computer and programming.
– The basics of what is an algorithm.
– How programming is a form of recipe.
– Different levels of languages.
– Syntax and Semantics.

More Related Content

Viewers also liked

Procurement- Contract Management
Procurement- Contract ManagementProcurement- Contract Management
Procurement- Contract Management
Business Services Support Limited
 
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
HIMADRI BANERJI
 
Public Procurement and Contract - Theory and practice in Nepal_2013
Public Procurement and Contract - Theory and practice in Nepal_2013Public Procurement and Contract - Theory and practice in Nepal_2013
Public Procurement and Contract - Theory and practice in Nepal_2013
Department of Urban Development and Building Construction (DUDBC)
 
Contract management general
Contract management generalContract management general
Contract management general
Vasudevan Deivasigamani
 
Vocabulary in use intermediate
Vocabulary in use intermediateVocabulary in use intermediate
Vocabulary in use intermediate
Omnia A. Abdullah
 
Construction Project Managment Techniques
Construction Project Managment TechniquesConstruction Project Managment Techniques
Construction Project Managment Techniques
guestc8140fe
 
Tendering in construction introduction
Tendering in construction introductionTendering in construction introduction
Tendering in construction introduction
Daniel Ross
 
Tender processing
Tender processingTender processing
Tender processing
dnyandev_d
 
Guide to Contract Management
Guide to Contract ManagementGuide to Contract Management
Guide to Contract Management
Berkman Solutions
 
The Project Management Process - Week 2
The Project Management Process - Week 2The Project Management Process - Week 2
The Project Management Process - Week 2
Craig Brown
 
Types of conract
Types of conractTypes of conract
Types of conract
Naveen_yadav
 
Tender procedure slide
Tender procedure slideTender procedure slide
Tender procedure slide
politeknik malaysia
 
Introduction to Contract Law
Introduction to Contract LawIntroduction to Contract Law
Introduction to Contract Law
theacademist
 
Types of Contract in Construction Management
Types of Contract in Construction ManagementTypes of Contract in Construction Management
Types of Contract in Construction Management
Shahin MB
 
Types of contract in Project management
Types of contract in Project managementTypes of contract in Project management
Types of contract in Project management
Ali Heydari
 
10 Contract Management Implementation Pitfalls | Selectica
10 Contract Management Implementation Pitfalls | Selectica10 Contract Management Implementation Pitfalls | Selectica
10 Contract Management Implementation Pitfalls | Selectica
Determine
 
EPC v EPCM Contracting- A Comparison
EPC v EPCM Contracting- A ComparisonEPC v EPCM Contracting- A Comparison
EPC v EPCM Contracting- A Comparison
helensuni
 
CONTRACTS AND ITS TYPES
CONTRACTS AND ITS TYPESCONTRACTS AND ITS TYPES
CONTRACTS AND ITS TYPES
Pundlik Rathod
 

Viewers also liked (18)

Procurement- Contract Management
Procurement- Contract ManagementProcurement- Contract Management
Procurement- Contract Management
 
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
Risk Assessment, Mitigation And Management In Epc Projects With Case Study By...
 
Public Procurement and Contract - Theory and practice in Nepal_2013
Public Procurement and Contract - Theory and practice in Nepal_2013Public Procurement and Contract - Theory and practice in Nepal_2013
Public Procurement and Contract - Theory and practice in Nepal_2013
 
Contract management general
Contract management generalContract management general
Contract management general
 
Vocabulary in use intermediate
Vocabulary in use intermediateVocabulary in use intermediate
Vocabulary in use intermediate
 
Construction Project Managment Techniques
Construction Project Managment TechniquesConstruction Project Managment Techniques
Construction Project Managment Techniques
 
Tendering in construction introduction
Tendering in construction introductionTendering in construction introduction
Tendering in construction introduction
 
Tender processing
Tender processingTender processing
Tender processing
 
Guide to Contract Management
Guide to Contract ManagementGuide to Contract Management
Guide to Contract Management
 
The Project Management Process - Week 2
The Project Management Process - Week 2The Project Management Process - Week 2
The Project Management Process - Week 2
 
Types of conract
Types of conractTypes of conract
Types of conract
 
Tender procedure slide
Tender procedure slideTender procedure slide
Tender procedure slide
 
Introduction to Contract Law
Introduction to Contract LawIntroduction to Contract Law
Introduction to Contract Law
 
Types of Contract in Construction Management
Types of Contract in Construction ManagementTypes of Contract in Construction Management
Types of Contract in Construction Management
 
Types of contract in Project management
Types of contract in Project managementTypes of contract in Project management
Types of contract in Project management
 
10 Contract Management Implementation Pitfalls | Selectica
10 Contract Management Implementation Pitfalls | Selectica10 Contract Management Implementation Pitfalls | Selectica
10 Contract Management Implementation Pitfalls | Selectica
 
EPC v EPCM Contracting- A Comparison
EPC v EPCM Contracting- A ComparisonEPC v EPCM Contracting- A Comparison
EPC v EPCM Contracting- A Comparison
 
CONTRACTS AND ITS TYPES
CONTRACTS AND ITS TYPESCONTRACTS AND ITS TYPES
CONTRACTS AND ITS TYPES
 

Similar to Introduction to programming01

CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
sti meycauayan
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
Lecture01 algorithm analysis
Lecture01 algorithm analysisLecture01 algorithm analysis
Lecture01 algorithm analysis
Zara Nawaz
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
Ashim Lamichhane
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Nida Chaudhary
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
Embedded C
Embedded CEmbedded C
Computational thinking
Computational thinkingComputational thinking
Computational thinking
r123457
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
C++ good tutorial
C++ good tutorialC++ good tutorial
C++ good tutorial
Ezzat Atalla
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
Nirmalavenkatachalam
 
Code tuning strategies
Code tuning strategiesCode tuning strategies
Code tuning strategies
Asha Sari
 
CPP01 - Introduction to C++
CPP01 - Introduction to C++CPP01 - Introduction to C++
CPP01 - Introduction to C++
Michael Heron
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
kapib57390
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
Michael Heron
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
TeddyDaka
 

Similar to Introduction to programming01 (20)

CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Lecture01 algorithm analysis
Lecture01 algorithm analysisLecture01 algorithm analysis
Lecture01 algorithm analysis
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
 
Lecture1
Lecture1Lecture1
Lecture1
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Computational thinking
Computational thinkingComputational thinking
Computational thinking
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
C++ good tutorial
C++ good tutorialC++ good tutorial
C++ good tutorial
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 
Code tuning strategies
Code tuning strategiesCode tuning strategies
Code tuning strategies
 
CPP01 - Introduction to C++
CPP01 - Introduction to C++CPP01 - Introduction to C++
CPP01 - Introduction to C++
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
 

Recently uploaded

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 

Recently uploaded (20)

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 

Introduction to programming01

  • 1. Nadim Ahmed Introduction to Programming 01 – Programming and Algorithms Nadim Ahmed
  • 2. Nadim Ahmed Introduction • You must bring a pen and some paper with you to write notes from the board. • This is a challenging subject, so do come to all lectures and labs, and make plenty of notes. • If you have any questions, then please ask.
  • 3. Nadim Ahmed How to Learn • I will give you exercises to do, so please do them. • You will NEVERNEVERNEVERNEVER learn programming by memorising! • Make sure you understandunderstandunderstandunderstand what is happening. • You must attempt the exercises by yourself.
  • 4. Nadim Ahmed What is a Computer? “They don’t get angry, they don’t get happy, they don’t get sad, they don’t laugh at your jokes. They just run programs.” Paraphrased from “Short Circuit”
  • 5. Nadim Ahmed What is a Computer? • Let us start at the beginning and see what is a computer. • A computer is a machine that can calculate and use logic to carry out tasks.
  • 6. Nadim Ahmed What is a Computer • Computers take in inputinputinputinput. – This is data that is given to the computer. • They processprocessprocessprocess the input. – This is when they manipulate/use the data. • They produce an outputoutputoutputoutput. – This is the result of manipulating the input.
  • 7. Nadim Ahmed What is Programming? • To get a computer to carry out different tasks, we have to be able to give it specific instructions. • This is programming. • Before we start programming, we have to look at something else.
  • 8. Nadim Ahmed Algorithms • Before writing a program, the programmer must understand what the result should be and how the program will produce it. • It is important to know that a computer program describes a computational procedure called an algorithm.
  • 9. Nadim Ahmed Algorithms • An algorithm is a step by step sequence of instructions that describes how to perform a computation. • An algorithm answers the question – “What method will you use to solve this computational problem?”
  • 10. Nadim Ahmed Algorithms • Only after – we clearly understand the desired result, – we clearly understand the algorithm and – know the specific steps required to produce the desired result • we can write the program.
  • 11. Nadim Ahmed Programming Programming is the translation of the selected algorithm into a language that the computer can use.
  • 12. Nadim Ahmed Programming Let’s see a real life example of what is programming.
  • 13. Nadim Ahmed Programming a Sponge Cake • Switch oven on at 180°C • Cream together 225g softened butter and 225g of sugar • Whisk 4 eggs and add to mixture slowly • Add 225g of sifted self raising flour and fold. • Grease two cake tins and add mixture. • Bake for 20 – 30 minutes until golden brown.
  • 14. Nadim Ahmed Programmable Computer • Can provide a computer a sequence of instructions describing the process I want it to execute. • Have a fixed set of primitives, can program almost anything. – In our sponge cake, the primitives are commands like •Cream, whisk, fold, grease.
  • 15. Nadim Ahmed Programming and Algorithms • To illustrate an algorithm, we will consider a simple requirement. • Assume that a program must calculate the average of three numbers. • Most people do not think algorithmically; – They tend to think intuitively.
  • 16. Nadim Ahmed Programming and Algorithms • If your car tyre needs changing, – you will not think of all the steps required, – you will either simply change the tyre or – call someone else to do the job. • This is an example of intuitive thinking.
  • 17. Nadim Ahmed Programming and Algorithms • Unfortunately, computers do not respond to intuitive commands. • A general statement such as “find average of three numbers” means nothing to a computer. – This is because computers can only respond to algorithmic commands written in an acceptable language such as C.
  • 18. Nadim Ahmed Programming and Algorithms • To program a computer successfully, you must clearly understand the difference between algorithmic and intuitive commands. • You must give the computer a detailed, step-by-step set of instructions that forms an algorithm.
  • 19. Nadim Ahmed Average of Three Numbers • We have to understand what the requirements are, and what the result will be. • To make it easier, let us identify the three numbers to use as an example.
  • 20. Nadim Ahmed Average of Three Numbers • We have chosen the numbers • 2, 3 and 10 Class Discussion:Class Discussion:Class Discussion:Class Discussion: What do we mean by “find the average of 2, 3 and 10”?
  • 21. Nadim Ahmed Average of Three Numbers • To find the average, we add up 2, 3 and 10. • Then we divide that by three. • 2 + 3 + 10 = 15 • 15 ÷ 3 = 5 • Therefore the average is 5.
  • 22. Nadim Ahmed Average of Three Numbers • We now know how to find the average of three specific numbers. • How are we going to make it a bit more general? • Think of what steps you will take to get the average of three numbers.
  • 23. Nadim Ahmed Average of Three Numbers Class Discussion:Class Discussion:Class Discussion:Class Discussion: What do we need to make a generic program to find the average of three numbers?
  • 24. Nadim Ahmed Average of Three Numbers • We need to get our three numbers. • We need to add the three numbers • We need to divide the total by 3.
  • 25. Nadim Ahmed Code Modularity • When programming, we break our large problem into modules – where each module can be thought of as a single task. • These modules make it easier to break down programming problems.
  • 26. Nadim Ahmed Making Pizza When making pizza, we have four basic tasks. • Make pizza base. • Make pizza topping. • Assemble topping on the base. • Bake pizza in oven. Each of these tasks can be thought of as a modulemodulemodulemodule, as they perform one task each.
  • 27. Nadim Ahmed Why Modules? • Programs that use modules are known as modular programsmodular programsmodular programsmodular programs. • Modular programs are easier to develop, correct and modify. – Since they split the tasks into separate modules, you can deal with each module individually. – If you have a mistake in one module, you don’t worry about it affecting other modules.
  • 28. Nadim Ahmed Modules • Each module is actually a small subprogram. • We break our module into smaller tasks. • Each module – InputInputInputInputs some data. – ProcessProcessProcessProcesses the data. – OutputOutputOutputOutputs the processed data.
  • 29. Nadim Ahmed A Pizza Module • For our pizza making program, let’s see our module “Make pizza topping”. • Let’s say the topping will be a “cheese and tomato” topping. • What will the input, process and output of the module be?
  • 30. Nadim Ahmed Make Pizza Topping • Input – Cheese – Tomato – Garlic – Green Peppers – Basil – Onion
  • 31. Nadim Ahmed Make Pizza Topping • Process – Gently heat up tomato, garlic, green peppers, basil and onion. – Blend the mixture – Grate the cheese and keep aside. • Output – Tomato sauce – Grated cheese
  • 32. Nadim Ahmed Add Module Class DiscussionClass DiscussionClass DiscussionClass Discussion • If we have a module that adds two numbers. • What are the – Inputs? – Processes? – Outputs?
  • 33. Nadim Ahmed Add Module • Inputs – Our two numbers that we want to add. – Let’s call them a and b • Process – Add the two numbers and keep the result safe. c = a + b • Output – The result which is stored in c
  • 34. Nadim Ahmed Modules Class DiscussionClass DiscussionClass DiscussionClass Discussion • We have a program that can convert between different types of distances. • These can be – kilometres to miles, – miles to kilometres, – inches to centimetres, – centimetres to inches. • If we have a program that converts different types of distances then we should break it down into modules. – What modules do we use?
  • 35. Nadim Ahmed Programming and Modules • We can have one module that converts from kilometres to miles, and another one to convert from miles to kilometres. • Also, we can have one module that converts from centimetres to inches and vice versa. • In other words, one module for each task.
  • 36. Nadim Ahmed How Will We Program the Computer? • We will now look at how we will program the computer. • We need to communicate with the computer so then we are understood by the computer. • I am speaking to you in English, which some of you understand. • We will now explore languages that humans can use with computers.
  • 37. Nadim Ahmed Levels of Languages • Computers work in binary – 0, 1 – Not very human readable. • To make things easier, we have various levels of languages. • These levels range from – HighHighHighHigh to – LowLowLowLow
  • 38. Nadim Ahmed Levels of Languages • Machine code is the lowest level of programming language. – This is the language that the CPU uses. – Tailored for each individual CPU. – If you write something for an ARM processor, it will not work on an Intel processor.
  • 39. Nadim Ahmed Multiplying in Low Level • This is an example of multiplying two numbers in a low level language. • It has been written for the Zilog Z80 microprocessor, which was very popular in the late 1970s until late 1980s. • There was no multiply command, so we had to add numbers several times.
  • 40. Nadim Ahmed Multiplying Two Numbers org &4000 ; store in memory location 4000 ld b,3 ; load register b with 3 ld a,0 ; load register a with 0 ; The following line is in memory location 4004 add a,2 ; add 2 to register a dec b ; decrement register b by 1. jp nz,&4004 ; jump if not zero to memory location 4004 ld (&400f),a ; Copy content of register a to location 400f end ; End of program
  • 44. Nadim Ahmed High Level Languages • In order to make programming easier, we use a high level language. • When we use a high level language, we need to convert it to machine code. – This is called compilingcompilingcompilingcompiling. – We use a compilercompilercompilercompiler to compile the sourcesourcesourcesource codecodecodecode into machine code. – Source code is our original high level code.
  • 45. Nadim Ahmed Multiplying in High Level • You saw just how much effort was required to multiply 3 by 2 in low level. • In a high level language, we can just do the following: 3*2
  • 46. Nadim Ahmed Syntax • Syntax deals with the grammar of the language. – So, if you are speaking English, and say: Cat ball hit. – You have a syntax error. •The cat hit the ball. • The compiler will tell you about syntax errors.
  • 47. Nadim Ahmed Semantic • However, if your grammar is correct, but the meaning is wrong, then you have a semantic error. The cat cooked some dolma. • The grammar is correct, but I very much doubt that a cat can actually cook dolma.
  • 48. Nadim Ahmed Semantic • Let’s say you wrote down that the area of a triangle is worked out by the following equation: length of base * height of triangle • You have a semantic error. • The compiler will not tell you that you have a mistake in the equation.
  • 49. Nadim Ahmed C • We will be using C as our high level programming language. • I have chosen ANSI C as it is a well known standard that can be used by most C compilers for different operating systems. • It is used widely by programmers and academics in systems and graphics programming.
  • 50. Nadim Ahmed In Summary • We have seen – What is a computer and programming. – The basics of what is an algorithm. – How programming is a form of recipe. – Different levels of languages. – Syntax and Semantics.