Programming Lecture 01
Programming Lecture 01
Computer Programming
Second Semester
Contents
• Introduction to problem solving,
• Introduction to programming,
• introduction to algorithms,
2
Contents
• conditional statements and execution flow for conditional statements,
• pointers/references,
4
Computer Programming
5
Why Programming?
6
Why Programming?
• Computer is just a dumb machine made up of different electronic
components. It is like a box which cannot do anything by itself.
• If we need our computer to perform some task, we first have to teach the
computer in detail “how it will accomplish that task?”
• Once the computer is taught about a particular task, it will completely obey
it but cannot do anything that it is not taught to.
7
Why Programming?
• Like the humans, we can teach the computer through communicating with it
using a particular language.
9
Programmer
• The person who gives the instructions (commands) to the computer is
known as the programmer.
10
Instruction
DO THIS!
11
Instruction
• Instruction is any command given to the computer.
• For example:
1) Add two variables A and B
2) Display result
3) Read file
12
Program
NOW DO THIS!
NOW DO THIS!
NOW DO THIS!
NOW DO THIS!
NOW DO THIS!
13
Program
• Program is a set (collection) of instruction to do a meaningful task.
14
Program
Instruction 1: Get first number from the user and store it in A variable
Instruction 2: Get second number from the user and store it in B variable
Instruction 3: Get third number from the user and store it in C variable
• Instructions 1-6 are used to solve a single task. This collection of instruction
is known as a program.
15
Programming Language
16
Programming Language
17
Programming Language
• Each language has a unique set of keywords (special words that it
understands) and a special syntax (format) for organizing program
instructions.
18
Types of Programming Languages
• There are three types of programming languages:
19
Low-Level Language
LANGUAGE
21
Low-Level Language
22
Machine Language
• It is one of the low level language.
• Here all the instructions are written as code of binary sequence. For
example:
• In order to do addition, the code is: 10010001
• In order to decrement a number by one, the code is: 11011011
• In order to move data from one place to another, the code is:
10000111
24
Machine Language
25
Machine Language
• Machine language program example:
10010010
11001010
01001010
11110101
00000101
00101000
11101010
10101010
26
Assembly Language
• Assembly language is same as machine language but uses English like
words to represent individual operations.
• For example: Instead of binary codes it uses : ADD, MOV, SUB, INC
• It is easier than the machine language but still it is very difficult to control
a larger program using assembly.
27
Assembly Language
28
Assembly Language
• Assembly language program example:
MVI A, 05h
MVI B, 9Ah
ADD B
INC A
STA 8200h
HLT
29
High-Level Language
LANGUAGE
• Like assembly language, it also uses English like words for the
operations.
33
High-Level Language
• High level language program example:
int main()
{
int a = 5;
int b = 6;
if(a > b)
cout<<“First number is greater.”;
else
cout<<“Second number is greater.”;
}
34
Middle-Level Language
LANGUAGE
• A language that has the features of both low level and high
level languages.
37
Source Code and Object Code
Source Code Object Code
• The set of instructions written in any • The set of instructions written in
language other than machine language is machine language is called as object
called as source code. code. It is also known as machine code.
38
Source Code and Object Code
Source Code Object Code
• It is in the form of text. • It is in the form of binary numbers.
39
Language Translators
40
Language Translators
CONVERT
Source Code Translator Object Code
Language Translator
41
Why Language Translators?
• Computer only understands object code (machine code).
• There must be a program that converts source code in to the object code
so that the computer can understand it.
• The programmer writes the source code and then translator converts it
in machine readable format (object code).
42
Types of Language Translators
• There are three types of language translator:
43
Assembler
CONVERT
Assembly
Assembler Object Code
Source Code
44
Compiler
45
Compiler
1 2 3 4
46
Interpreter
47
Interpreter
Program
48
Difference between Compiler and Interpreter
Compiler Interpreter
• It converts whole code at a time. • It converts the code line by line.
• It is faster. • It is slower.
• Errors are displayed after entire program • Errors are displayed for every instruction
is checked. interpreted (if any).
49
Bug
50
Bug
51
Bug
• The term bug was used by Grace Hopper in 1946.
• Hopper used to work on Mark II computer, there some error
occurred in the system. The cause of the error was a moth
(bug) trapped in a relay creating short circuit.
52
Debugging
53
Debugging
• It is the process of finding and fixing the bugs (errors) in the
program.
54