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
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
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
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
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
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.
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.
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.
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