SlideShare ist ein Scribd-Unternehmen logo
1 von 81
Computer Programming
Day 1
- Ijasali Manalody
Relevance of computer Programming
• To automate tasks done by Humans
Hard Work
Difficult to
generate reports
Delay in
handling bulk
data
Easy to
Maintain
Single click for
reports
Can handle
any amount
of data
What is programming?
• Series of instructions to a computer to accomplish a task;
– Same like instructions given to human to perform a task
• Eg : Go straight , Take right etc
• Group of instructions will make a program to perform that particular task
Group of instructions to make Tea is,
Instruction 1 : Boil Water
Instruction 2 : Put Tea powder
Instruction 3 : Put Sugar
Group of instructions
make a program
How to give instructions to computer?
• Instructions must be written in a way the computer can
understand
漢鼎 31 繁 81 印篆
?????
Add 31 and 81
????
Language of Computer
• Computer only understands Machine language which is of 0 and 1
• So any instructions to computer must be of Machine Language
Mother Board
How does a Computer program get executed?
Instruction Address
11011110 00110000
00010010 00110001
10000000 00001010
01001000 10000001
00001100 10000100
11000001 00101011
01011011 01011001
11101011 11111000
Ram
Loads instruction for execution
CPU
Ram
Example
Machine
Instruction
Machine Operation
0000 0000 Stop
0000 0001 Rotate bristles left
0000 0010
Rotate bristles
right
0000 0100
Go back to start of
program
• Let us say that an electric toothbrush has a processor and main memory.
• The processor can rotate the bristles left and right, and can check the on/off switch
Addr
ess
Machine
Instructions
0 0000 0001
1 0000 0010
2 0000 0100
3
4
Types of Languages
• Machine level Languages
• Machine language programs were made up of instructions written in binary
code.
• This is the “native” language of the computer.
• Assembly Level Languages
• Assembly language programs are made up of instructions written in
mnemonics.(Uses convenient alphabetic abbreviations to represent instructions)
• High Level Languages
• Use statements that resemble English phrases combined with mathematical
terms needed to express the problem or task being programmed.
“All programs must be translated to Machine language
before their instructions can be executed ”
Assembler
• Assembled languages:
– Assembler: a program used to translate Assembly language programs.
– Produces one line of binary code per original program statement.
– The entire program is assembled before the program is sent to the
computer for execution.
......
clc
add ax,bx
mov di,
offset result
.....
Assembler
......
01010101
01010101
......
Compiler
– Compiler is a program used to translate high-level programs into
Machine level program.
– It translates the entire program into binary code before anything is sent
to the CPU for execution.
......
c=a+b ;
Print a;
......
Compiler
......
01010101
01010101
......
Interpreter
• Interpreted Languages:
– Interpreter: A program used to translate high-level programs.
– Translates one line of the program into binary code at a time:
• An instruction is fetched from the original source code.
• The Interpreter checks the single instruction for errors. (If an error is found,
translation and execution ceases. Otherwise…)
• The instruction is translated into binary code.
• The binary coded instruction is executed.
• The fetch and execute process repeats for the entire program.
......
c=a+b ;
Print a;
......
Interpretor
......
01010101
01010101
......
Compiler Vs Interpreter
• Takes Entire Program as input
• Intermediate object code is generated
• Program need not be compiled every
time we run the program
• Errors are displayed after entire
program is checked
• Example : C compiler
• Takes Single instruction as input
• No intermediate object code is
generated
• Every time we run the program it will
be converted to low level
program(interpreted)
• Errors are displayed after every
instruction interpreted
• Example : BASIC, PHP interpreter
Programming languages Vs Scripting Languages
• Some programming languages (like Java or C++) require the code
to be compiled (translated to binary) before it can be started.
• Others (like JavaScript,PHP) are interpreted, meaning that each
command is translated separately when the program is started.
How to write a program?
Step 1: Decide what steps are needed to complete the task !
Step 2: Write the steps as Algorithms(written in English) or as a flowchart
(graphic symbols)
Step 3: Translate into the programming language
Step 4: Try out the program and “debug” it (fix if necessary)
What is Algorithms?
• List of steps written in English
• Like the instructions for a recipe
• Must be in the right sequence
– Imagine saying “put the tea powder” and then “take water and boil”
Sample Algorithm
• Task: add two numbers
• Algorithm:
– Start
– Get two numbers
– Add them
– Print the answer
– End
What does a flowchart look like?
• The algorithm from the previous slide would look like this as a
flowchart: Start
Get 2 numbers
Add them
Print answer
End
What are those symbols?
• START/END
• INPUT/OUTPUT
• PROCESS
• DECISION
What are those symbols?
• START/END
• Used at the beginning and end of each flowchart.
What are those symbols?
• INPUT/OUTPUT
• Shows when information/data comes into a program or is
printed out.
What are those symbols?
• PROCESS
• Used to show calculations, storing of data in variables, and other
“processes” that take place within a program.
What are those symbols?
• DECISION
• Used to show that the program must decide whether something (usually a
comparison between numbers) is true or false. YES and NO (or T/F)
branches are usually shown.
Y
N
X>7?
Another Sample: Calculating Age
• Algorithm:
– Start
– Get year born
– Calculate age
– Print age
– If age > 50 print OLD
– End
Another Sample: Calculating Age
Get yr
Calc age
Print age
Age>50?OLD Y
N
Start
End
Questions?
“A good question deserve a good grade…”
Self Check !!
Self-Check
• A computer program is…
– A series of instructions to accomplish something
– Written in High level language
– Written in machine language
– All of the above
Self-Check
• A computer program is…
– A series of instructions to accomplish something
– Written in High level language
– Written in machine language
– All of the above
Self-Check
• To “compile” a program means to…
– Translate it into mnemonics
– Translate it into binary code
– Executes the program
– Run the program instruction
• To “compile” a program means to…
– Translate it into mnemonics
– Translate it into binary code
– Executes the program
– Run the program instruction
Self-Check
Self-Check
• Algorithm is…
– The program as it is written in a programming language
– The results of a program that makes secret codes
– The logic of a program written in English
– The logic of a program shown in a chart
• Algorithm is…
– The program as it is written in a programming language
– The results of a program that makes secret codes
– The logic of a program written in English
– The logic of a program shown in a chart
Self-Check
Self-Check
• The flowchart symbol to perform a calculation is…
Self-Check
• The flowchart symbol to perform a calculation is…
Self-Check
• The flowchart symbol to perform a Decision is…
• The flowchart symbol to perform a Decision is…
Self-Check
Self-Check
• Look at the flowchart section below. If the variable X is 5, what
will print (K or 1st)?
X > 5?
YN
Print “1st”Print “K”
Self-Check
• Look at the flowchart section below. If the variable X is 5, what
will print (K or 1st)?
X > 5?
YN
Print “1st”Print “K”
K will be printed. The answer to the question “Is X greater than 5?”
is NO, since X is equal to (not greater than) 5.
Self-Check
• Choose the correct
flowchart symbol for each
of these statements.
• AGE>65?
• Calc. Tax
• START
• Print NAME
Self-Check
• Choose the correct
flowchart symbol for each
of these statements.
• AGE>65?
• Calc. Tax
• START
• Print NAME
“End of Day 1”
Check list Day1
• Relevance of Computer programming
• Instructions are loaded into ____
• Instructions are executed by ____
• Assembly level Language Vs Machine level language Vs
High level language
• Assembler Vs compiler Vs interpreter
Elements of a Program
Day 2
How does human perform simple task; for Eg: add 456 and 44
Add 456
and 44 500
How does human perform simple task; Eg: add 456 and 44
1 We Hear it through our input senses
2 We store the numbers 456 and 44 in our memory
456
44
456+44 3 We calculate the result in our brain and store it in
memory
500
3 We say the answer through our output senses
1 Computer use keyboard to receive inputs
2 Computer store the numbers 456 and 44 in Ram
456
44
456+44
3
Computer calculate the result in CPU (ALU within
CPU) and stores result back in ram
500
4 Computer use monitor to display outputs
How does computer perform simple task; Eg: add 456 and 44
Elements of a Program
• During programming we may need to do the following
– Stores Data temporarily
– Control the normal flow of instruction execution
– Repeat one or more instructions several time
– Repeat group of instructions at several parts of program
Elements of a Program
• During programming we may need come across following situations
– Stores Data temporarily - Variables
– Control the normal flow of instruction execution - Decisions
– Repeat one or more instructions several time - Loops
– Repeat particular instructions at several parts of program - Functions
Variables
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers up to 100
i=i+1
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers upto 100
i=i+1
1i
Ram
• Variables are part of almost every program.
• A variable is a “place to put data” and is usually represented by a letter
or a word. (Think of a variable as a Tupperware container with a
label on it.)
• Variable names cannot contain spaces.
R
A
M
Variables
A B c
Variables
• The most common way to put information into a variable is to use the
equal sign (=).
• Eg a=10;
• C = A + 7 means take the value of A, add 7, and put it into C.
• COUNT=COUNT + 2 means take the current value of COUNT, add
2 to it, and make it the new value of COUNT.
Variables
• Sometimes you must specify the type of data that will be placed in a
variable.
• Here are some examples of data types:
– String (text, “strings of letters”)
– Integer (whole numbers)
– Float(decimal numbers)
– Boolean (true/false)
Variables
• Variables may be classified as global or local.
• A global variable is one that can be shared by all parts of a program,
including any functions or sub-programs.
• A local variable is one that is used only within a certain part of the
program, for example, only in one function or sub-program.
Decisions
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers up to 100
i=i+1
Decisions
• A program often needs to decide whether something is true or
false in order to see which way to continue.
• Programs often use IF (or IF or IF ELSE) statements to show a
decision.
Decisions
• An IF statement always has a condition to check, often a
comparison between a variable and a number.
• The IF statement also must specify what to do if the
condition/comparison is true.
Decisions
• In an IF statement, when the condition is false, the program
simply ignores the commands within IF and continues to the next
line.
• In an IF ELSE statement, commands are given for both the true
and false conditions.
Loops
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers up to 100
i=i+1
Loops
• A loop is a repetition of all or part of the commands in a program.
• A loop often has a counter (a variable) and continues to repeat a
specified number of times.
• A loop may also continue until a certain condition is met (e.g.,
until the end of a file or until a number reaches a set limit)
Functions
Print all the numbers up to 100
N Y
Start
i=1
If
i<
10
0
Print iStop
i=i+1
Start
STOP
Functions
• In most programming languages, small sub-programs are used to
perform some of the tasks.
• These may be called functions, subroutines, handlers, or other such
terms.
• Functions often have names (e.g., getName or CALCTAX).
Functions
• A function generally gets information from the main program,
performs some task, and returns information back to the program.
• Functions follow the same rules of syntax, etc. as the main program.
Hints for Writing Code
• “Code” means writing the program in the appropriate language
• Be sure the code is exact (spelling, capitals/lower case,
punctuation, etc).
• Write part of the code, try it, then write more.
Debugging
• To “debug” means to try a program, then fix any mistakes.
• Virtually no program works the first time you run it. There are just too
many places to make errors.
• When you are debugging a program, look for spelling and punctuation
errors.
• Fix one error at a time, then try the program again.
Questions?
“A good question deserve a good grade…”
Self Check !!
Self-Check
• A function in a program is…
– Something from trigonometry, like COSINE
– A sub-program, usually performing one task
– A way to check the accuracy of a program (a “function check”)
• A function in a program is…
– Something that stores a value
– A sub-program, usually performing one task
– A way to check the accuracy of a program (a “function check”)
Self-Check
Self-Check
• A variable in a program is…
– A letter or word that represents a place to store data
– A decision made within a program
– A small sub-program used to find errors
Self-Check
• A variable in a program is…
– A letter or word that represents a place to store data
– A decision made within a program
– A small sub-program used to find errors
• A global variable in a program is…
– Store data Permanently
– Store Data that can not be accessed from functions
– Store data than can be accessed from anywhere in the program
Self-Check
• A global variable in a program is…
– Store data Permanently
– Store Data that can not be accessed from functions
– Store data than can be accessed from anywhere in the program
Self-Check
• A loop is used in a program when…
– One or more instructions repeats at several part of the program
– You want to skip particular instructions
– You want to repeat particular instructions until a condition to satisfy
– All of the above
Self-Check
• A loop is used in a program when…
– One or more instructions repeats at several part of the program
– You want to skip particular instructions
– You want to repeat particular instructions until a condition to satisfy
– All of the above
Self-Check
“End of Day 2”

Weitere ähnliche Inhalte

Was ist angesagt?

Number system
Number systemNumber system
Number systemGagan Deep
 
Computer Language
Computer LanguageComputer Language
Computer LanguageDeepak Yadav
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing ThesisHemant Sharma
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer ProgrammingProf. Erwin Globio
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm IntroductionAshim Lamichhane
 
Introduction to Computers Lecture # 3
Introduction to Computers Lecture # 3Introduction to Computers Lecture # 3
Introduction to Computers Lecture # 3Sehrish Rafiq
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming LanguagesJuhi Bhoyar
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1REHAN IJAZ
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of ComputationShiraz316
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manualTanzeem Syed
 
Program & language generation
Program & language generationProgram & language generation
Program & language generationBuxoo Abdullah
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automatadeepinderbedi
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An IntroKimberly De Guzman
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory Rajendran
 
Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming LanguagesTarun Sharma
 

Was ist angesagt? (20)

Number system
Number systemNumber system
Number system
 
Computer Language
Computer LanguageComputer Language
Computer Language
 
Introduction to programming languages
Introduction to programming languagesIntroduction to programming languages
Introduction to programming languages
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing Thesis
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Introduction to Computers Lecture # 3
Introduction to Computers Lecture # 3Introduction to Computers Lecture # 3
Introduction to Computers Lecture # 3
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming Languages
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of Computation
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Program & language generation
Program & language generationProgram & language generation
Program & language generation
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An Intro
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
 
Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming Languages
 

Andere mochten auch

Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...
Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...
Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...Media4math
 
A simple study on computer algorithms by S. M. Risalat Hasan Chowdhury
A simple study on computer algorithms by S. M. Risalat Hasan ChowdhuryA simple study on computer algorithms by S. M. Risalat Hasan Chowdhury
A simple study on computer algorithms by S. M. Risalat Hasan ChowdhuryS. M. Risalat Hasan Chowdhury
 
Inventions: The computer
Inventions: The computerInventions: The computer
Inventions: The computerandreasupertino
 
Nuclear power
Nuclear powerNuclear power
Nuclear powerAparna
 
On The Day the Last Nuclear Weapon is Destroyed
On The Day the Last Nuclear Weapon is DestroyedOn The Day the Last Nuclear Weapon is Destroyed
On The Day the Last Nuclear Weapon is Destroyedkenleybutler
 
Topic 1 intro power and ideas
Topic 1 intro power and ideasTopic 1 intro power and ideas
Topic 1 intro power and ideasHafidz Haron
 
Algorithms Vs Meta Language
Algorithms Vs Meta LanguageAlgorithms Vs Meta Language
Algorithms Vs Meta LanguageKelly Bauer
 
D3 (drought management and risk reduction in pakistan) brig. kamran shariff
D3 (drought management and risk reduction in pakistan)  brig. kamran shariffD3 (drought management and risk reduction in pakistan)  brig. kamran shariff
D3 (drought management and risk reduction in pakistan) brig. kamran shariffmuneeb khalid khalid muneeb
 
Golda Meir And Arab Israeli Relations 35 Years After[1]
Golda Meir And Arab Israeli Relations 35 Years After[1]Golda Meir And Arab Israeli Relations 35 Years After[1]
Golda Meir And Arab Israeli Relations 35 Years After[1]Hackelmeier_Library
 
Topic.09 The Civil Rights Movement
Topic.09 The Civil Rights MovementTopic.09 The Civil Rights Movement
Topic.09 The Civil Rights Movementmr.meechin
 
Cold war Photo Essay World History
Cold war Photo Essay World HistoryCold war Photo Essay World History
Cold war Photo Essay World HistoryTorresTroll
 
The Invention of Nuclear Weapons
The Invention of Nuclear WeaponsThe Invention of Nuclear Weapons
The Invention of Nuclear Weaponskryackey
 
Chapter9
Chapter9Chapter9
Chapter9Dang Tuan
 

Andere mochten auch (20)

Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...
Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...
Tutorials--The Language of Math--Variable Expressions--Multiplication and Sub...
 
A simple study on computer algorithms by S. M. Risalat Hasan Chowdhury
A simple study on computer algorithms by S. M. Risalat Hasan ChowdhuryA simple study on computer algorithms by S. M. Risalat Hasan Chowdhury
A simple study on computer algorithms by S. M. Risalat Hasan Chowdhury
 
Flowcharts
FlowchartsFlowcharts
Flowcharts
 
Inventions: The computer
Inventions: The computerInventions: The computer
Inventions: The computer
 
Nuclear power
Nuclear powerNuclear power
Nuclear power
 
On The Day the Last Nuclear Weapon is Destroyed
On The Day the Last Nuclear Weapon is DestroyedOn The Day the Last Nuclear Weapon is Destroyed
On The Day the Last Nuclear Weapon is Destroyed
 
Topic 1 intro power and ideas
Topic 1 intro power and ideasTopic 1 intro power and ideas
Topic 1 intro power and ideas
 
Algorithms Vs Meta Language
Algorithms Vs Meta LanguageAlgorithms Vs Meta Language
Algorithms Vs Meta Language
 
D3 (drought management and risk reduction in pakistan) brig. kamran shariff
D3 (drought management and risk reduction in pakistan)  brig. kamran shariffD3 (drought management and risk reduction in pakistan)  brig. kamran shariff
D3 (drought management and risk reduction in pakistan) brig. kamran shariff
 
Nuclear power plant
Nuclear power plantNuclear power plant
Nuclear power plant
 
fortigate
fortigatefortigate
fortigate
 
Golda Meir And Arab Israeli Relations 35 Years After[1]
Golda Meir And Arab Israeli Relations 35 Years After[1]Golda Meir And Arab Israeli Relations 35 Years After[1]
Golda Meir And Arab Israeli Relations 35 Years After[1]
 
Topic.09 The Civil Rights Movement
Topic.09 The Civil Rights MovementTopic.09 The Civil Rights Movement
Topic.09 The Civil Rights Movement
 
WWI 5 Weapons
WWI 5 WeaponsWWI 5 Weapons
WWI 5 Weapons
 
Cold war Photo Essay World History
Cold war Photo Essay World HistoryCold war Photo Essay World History
Cold war Photo Essay World History
 
The Invention of Nuclear Weapons
The Invention of Nuclear WeaponsThe Invention of Nuclear Weapons
The Invention of Nuclear Weapons
 
27 NP Completness
27 NP Completness27 NP Completness
27 NP Completness
 
Egypt
EgyptEgypt
Egypt
 
Chapter9
Chapter9Chapter9
Chapter9
 
A global picture of drought occurrence, magnitude, and preparedness
A global picture of drought occurrence, magnitude, and preparednessA global picture of drought occurrence, magnitude, and preparedness
A global picture of drought occurrence, magnitude, and preparedness
 

Ähnlich wie Algorithms - Introduction to computer programming

01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptxJustineLincopinesAlm
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
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.pptxTeddyDaka
 
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
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer ProgrammingAllen de Castro
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_progTAlha MAlik
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxgogulram2
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycleDhana malar
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptxarifaqazi2
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsSasidharaRaoMarrapu
 
CHAPTER-1.ppt
CHAPTER-1.pptCHAPTER-1.ppt
CHAPTER-1.pptTekle12
 
Lesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxLesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxAlinaMishra7
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 

Ähnlich wie Algorithms - Introduction to computer programming (20)

Programming
ProgrammingProgramming
Programming
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
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
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptx
 
PROBLEM SOLVING.pptx
PROBLEM SOLVING.pptxPROBLEM SOLVING.pptx
PROBLEM SOLVING.pptx
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
 
Cse
CseCse
Cse
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
 
CHAPTER-1.ppt
CHAPTER-1.pptCHAPTER-1.ppt
CHAPTER-1.ppt
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
Lesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxLesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptx
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 

Mehr von baabtra.com - No. 1 supplier of quality freshers

Mehr von baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

KĂźrzlich hochgeladen

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vĂĄzquez
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

KĂźrzlich hochgeladen (20)

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Algorithms - Introduction to computer programming

  • 1. Computer Programming Day 1 - Ijasali Manalody
  • 2. Relevance of computer Programming • To automate tasks done by Humans Hard Work Difficult to generate reports Delay in handling bulk data Easy to Maintain Single click for reports Can handle any amount of data
  • 3. What is programming? • Series of instructions to a computer to accomplish a task; – Same like instructions given to human to perform a task • Eg : Go straight , Take right etc • Group of instructions will make a program to perform that particular task Group of instructions to make Tea is, Instruction 1 : Boil Water Instruction 2 : Put Tea powder Instruction 3 : Put Sugar Group of instructions make a program
  • 4. How to give instructions to computer? • Instructions must be written in a way the computer can understand 漢鼎 31 皁 81 印篆 ????? Add 31 and 81 ????
  • 5. Language of Computer • Computer only understands Machine language which is of 0 and 1 • So any instructions to computer must be of Machine Language
  • 6. Mother Board How does a Computer program get executed? Instruction Address 11011110 00110000 00010010 00110001 10000000 00001010 01001000 10000001 00001100 10000100 11000001 00101011 01011011 01011001 11101011 11111000 Ram Loads instruction for execution CPU
  • 7. Ram Example Machine Instruction Machine Operation 0000 0000 Stop 0000 0001 Rotate bristles left 0000 0010 Rotate bristles right 0000 0100 Go back to start of program • Let us say that an electric toothbrush has a processor and main memory. • The processor can rotate the bristles left and right, and can check the on/off switch Addr ess Machine Instructions 0 0000 0001 1 0000 0010 2 0000 0100 3 4
  • 8. Types of Languages • Machine level Languages • Machine language programs were made up of instructions written in binary code. • This is the “native” language of the computer. • Assembly Level Languages • Assembly language programs are made up of instructions written in mnemonics.(Uses convenient alphabetic abbreviations to represent instructions) • High Level Languages • Use statements that resemble English phrases combined with mathematical terms needed to express the problem or task being programmed.
  • 9. “All programs must be translated to Machine language before their instructions can be executed ”
  • 10. Assembler • Assembled languages: – Assembler: a program used to translate Assembly language programs. – Produces one line of binary code per original program statement. – The entire program is assembled before the program is sent to the computer for execution. ...... clc add ax,bx mov di, offset result ..... Assembler ...... 01010101 01010101 ......
  • 11. Compiler – Compiler is a program used to translate high-level programs into Machine level program. – It translates the entire program into binary code before anything is sent to the CPU for execution. ...... c=a+b ; Print a; ...... Compiler ...... 01010101 01010101 ......
  • 12. Interpreter • Interpreted Languages: – Interpreter: A program used to translate high-level programs. – Translates one line of the program into binary code at a time: • An instruction is fetched from the original source code. • The Interpreter checks the single instruction for errors. (If an error is found, translation and execution ceases. Otherwise…) • The instruction is translated into binary code. • The binary coded instruction is executed. • The fetch and execute process repeats for the entire program. ...... c=a+b ; Print a; ...... Interpretor ...... 01010101 01010101 ......
  • 13. Compiler Vs Interpreter • Takes Entire Program as input • Intermediate object code is generated • Program need not be compiled every time we run the program • Errors are displayed after entire program is checked • Example : C compiler • Takes Single instruction as input • No intermediate object code is generated • Every time we run the program it will be converted to low level program(interpreted) • Errors are displayed after every instruction interpreted • Example : BASIC, PHP interpreter
  • 14. Programming languages Vs Scripting Languages • Some programming languages (like Java or C++) require the code to be compiled (translated to binary) before it can be started. • Others (like JavaScript,PHP) are interpreted, meaning that each command is translated separately when the program is started.
  • 15. How to write a program? Step 1: Decide what steps are needed to complete the task ! Step 2: Write the steps as Algorithms(written in English) or as a flowchart (graphic symbols) Step 3: Translate into the programming language Step 4: Try out the program and “debug” it (fix if necessary)
  • 16. What is Algorithms? • List of steps written in English • Like the instructions for a recipe • Must be in the right sequence – Imagine saying “put the tea powder” and then “take water and boil”
  • 17. Sample Algorithm • Task: add two numbers • Algorithm: – Start – Get two numbers – Add them – Print the answer – End
  • 18. What does a flowchart look like? • The algorithm from the previous slide would look like this as a flowchart: Start Get 2 numbers Add them Print answer End
  • 19. What are those symbols? • START/END • INPUT/OUTPUT • PROCESS • DECISION
  • 20. What are those symbols? • START/END • Used at the beginning and end of each flowchart.
  • 21. What are those symbols? • INPUT/OUTPUT • Shows when information/data comes into a program or is printed out.
  • 22. What are those symbols? • PROCESS • Used to show calculations, storing of data in variables, and other “processes” that take place within a program.
  • 23. What are those symbols? • DECISION • Used to show that the program must decide whether something (usually a comparison between numbers) is true or false. YES and NO (or T/F) branches are usually shown. Y N X>7?
  • 24. Another Sample: Calculating Age • Algorithm: – Start – Get year born – Calculate age – Print age – If age > 50 print OLD – End
  • 25. Another Sample: Calculating Age Get yr Calc age Print age Age>50?OLD Y N Start End
  • 26. Questions? “A good question deserve a good grade…”
  • 28. Self-Check • A computer program is… – A series of instructions to accomplish something – Written in High level language – Written in machine language – All of the above
  • 29. Self-Check • A computer program is… – A series of instructions to accomplish something – Written in High level language – Written in machine language – All of the above
  • 30. Self-Check • To “compile” a program means to… – Translate it into mnemonics – Translate it into binary code – Executes the program – Run the program instruction
  • 31. • To “compile” a program means to… – Translate it into mnemonics – Translate it into binary code – Executes the program – Run the program instruction Self-Check
  • 32. Self-Check • Algorithm is… – The program as it is written in a programming language – The results of a program that makes secret codes – The logic of a program written in English – The logic of a program shown in a chart
  • 33. • Algorithm is… – The program as it is written in a programming language – The results of a program that makes secret codes – The logic of a program written in English – The logic of a program shown in a chart Self-Check
  • 34. Self-Check • The flowchart symbol to perform a calculation is…
  • 35. Self-Check • The flowchart symbol to perform a calculation is…
  • 36. Self-Check • The flowchart symbol to perform a Decision is…
  • 37. • The flowchart symbol to perform a Decision is… Self-Check
  • 38. Self-Check • Look at the flowchart section below. If the variable X is 5, what will print (K or 1st)? X > 5? YN Print “1st”Print “K”
  • 39. Self-Check • Look at the flowchart section below. If the variable X is 5, what will print (K or 1st)? X > 5? YN Print “1st”Print “K” K will be printed. The answer to the question “Is X greater than 5?” is NO, since X is equal to (not greater than) 5.
  • 40. Self-Check • Choose the correct flowchart symbol for each of these statements. • AGE>65? • Calc. Tax • START • Print NAME
  • 41. Self-Check • Choose the correct flowchart symbol for each of these statements. • AGE>65? • Calc. Tax • START • Print NAME
  • 42. “End of Day 1”
  • 43. Check list Day1 • Relevance of Computer programming • Instructions are loaded into ____ • Instructions are executed by ____ • Assembly level Language Vs Machine level language Vs High level language • Assembler Vs compiler Vs interpreter
  • 44. Elements of a Program Day 2
  • 45. How does human perform simple task; for Eg: add 456 and 44 Add 456 and 44 500
  • 46. How does human perform simple task; Eg: add 456 and 44 1 We Hear it through our input senses 2 We store the numbers 456 and 44 in our memory 456 44 456+44 3 We calculate the result in our brain and store it in memory 500 3 We say the answer through our output senses
  • 47. 1 Computer use keyboard to receive inputs 2 Computer store the numbers 456 and 44 in Ram 456 44 456+44 3 Computer calculate the result in CPU (ALU within CPU) and stores result back in ram 500 4 Computer use monitor to display outputs How does computer perform simple task; Eg: add 456 and 44
  • 48. Elements of a Program • During programming we may need to do the following – Stores Data temporarily – Control the normal flow of instruction execution – Repeat one or more instructions several time – Repeat group of instructions at several parts of program
  • 49. Elements of a Program • During programming we may need come across following situations – Stores Data temporarily - Variables – Control the normal flow of instruction execution - Decisions – Repeat one or more instructions several time - Loops – Repeat particular instructions at several parts of program - Functions
  • 51. N Y Start i=1 If i<100 Print iStop Print all the numbers up to 100 i=i+1
  • 52. N Y Start i=1 If i<100 Print iStop Print all the numbers upto 100 i=i+1 1i Ram
  • 53. • Variables are part of almost every program. • A variable is a “place to put data” and is usually represented by a letter or a word. (Think of a variable as a Tupperware container with a label on it.) • Variable names cannot contain spaces. R A M Variables A B c
  • 54. Variables • The most common way to put information into a variable is to use the equal sign (=). • Eg a=10; • C = A + 7 means take the value of A, add 7, and put it into C. • COUNT=COUNT + 2 means take the current value of COUNT, add 2 to it, and make it the new value of COUNT.
  • 55. Variables • Sometimes you must specify the type of data that will be placed in a variable. • Here are some examples of data types: – String (text, “strings of letters”) – Integer (whole numbers) – Float(decimal numbers) – Boolean (true/false)
  • 56. Variables • Variables may be classified as global or local. • A global variable is one that can be shared by all parts of a program, including any functions or sub-programs. • A local variable is one that is used only within a certain part of the program, for example, only in one function or sub-program.
  • 58. N Y Start i=1 If i<100 Print iStop Print all the numbers up to 100 i=i+1
  • 59. Decisions • A program often needs to decide whether something is true or false in order to see which way to continue. • Programs often use IF (or IF or IF ELSE) statements to show a decision.
  • 60. Decisions • An IF statement always has a condition to check, often a comparison between a variable and a number. • The IF statement also must specify what to do if the condition/comparison is true.
  • 61. Decisions • In an IF statement, when the condition is false, the program simply ignores the commands within IF and continues to the next line. • In an IF ELSE statement, commands are given for both the true and false conditions.
  • 62. Loops
  • 63. N Y Start i=1 If i<100 Print iStop Print all the numbers up to 100 i=i+1
  • 64. Loops • A loop is a repetition of all or part of the commands in a program. • A loop often has a counter (a variable) and continues to repeat a specified number of times. • A loop may also continue until a certain condition is met (e.g., until the end of a file or until a number reaches a set limit)
  • 66. Print all the numbers up to 100 N Y Start i=1 If i< 10 0 Print iStop i=i+1 Start STOP
  • 67. Functions • In most programming languages, small sub-programs are used to perform some of the tasks. • These may be called functions, subroutines, handlers, or other such terms. • Functions often have names (e.g., getName or CALCTAX).
  • 68. Functions • A function generally gets information from the main program, performs some task, and returns information back to the program. • Functions follow the same rules of syntax, etc. as the main program.
  • 69. Hints for Writing Code • “Code” means writing the program in the appropriate language • Be sure the code is exact (spelling, capitals/lower case, punctuation, etc). • Write part of the code, try it, then write more.
  • 70. Debugging • To “debug” means to try a program, then fix any mistakes. • Virtually no program works the first time you run it. There are just too many places to make errors. • When you are debugging a program, look for spelling and punctuation errors. • Fix one error at a time, then try the program again.
  • 71. Questions? “A good question deserve a good grade…”
  • 73. Self-Check • A function in a program is… – Something from trigonometry, like COSINE – A sub-program, usually performing one task – A way to check the accuracy of a program (a “function check”)
  • 74. • A function in a program is… – Something that stores a value – A sub-program, usually performing one task – A way to check the accuracy of a program (a “function check”) Self-Check
  • 75. Self-Check • A variable in a program is… – A letter or word that represents a place to store data – A decision made within a program – A small sub-program used to find errors
  • 76. Self-Check • A variable in a program is… – A letter or word that represents a place to store data – A decision made within a program – A small sub-program used to find errors
  • 77. • A global variable in a program is… – Store data Permanently – Store Data that can not be accessed from functions – Store data than can be accessed from anywhere in the program Self-Check
  • 78. • A global variable in a program is… – Store data Permanently – Store Data that can not be accessed from functions – Store data than can be accessed from anywhere in the program Self-Check
  • 79. • A loop is used in a program when… – One or more instructions repeats at several part of the program – You want to skip particular instructions – You want to repeat particular instructions until a condition to satisfy – All of the above Self-Check
  • 80. • A loop is used in a program when… – One or more instructions repeats at several part of the program – You want to skip particular instructions – You want to repeat particular instructions until a condition to satisfy – All of the above Self-Check
  • 81. “End of Day 2”