Karwan University
Introduction to Programming
BY:
SAYED WASIULLAH (SADAT)
1
WHAT IS COMPUTER PROGRAMMING?
Computer programming is defined as the
process of creating computer software using
a programming language.
Computer programs are written by Human
individuals (Programmers).
A computer program is a set of instructions
that tell a computer what to do.
A program is created using a programming
language.
2
Who is a Programmer?
A programmer is a person
who writes the required computer programs
or applications by giving the computer
specific programming instructions.
Programmers translate the expected tasks
Into a form machines can understand.
3
LANGUAGE?
Language is a source of communication among
people.
It is medium of Expression
What is the computer language?
To establish a communication between user and
computer .
In general, there are two classes of languages
Natural languages
Programming Languages
4
Natural languages
These are the languages through which the human beings
communicate with each other. For example: English, Urdu, French,
Pashto etc.
Programming languages
These are the languages through which the human beings
communicate with the computer. These are the most widely used
mediums between the user and the computer. Examples are
C(Compiler), C++, COBOL, PASCAL, BASIC, FORTRAN etc.
The programming languages are classified into two
types:
1) Low level languages.
2) High level languages
5
1) Low-Level Language
It consists of two types of languages
Machine language
Machine Language was the first language used for
computers as a source of communication This is the only
language which is directly understandable by the machine
(computer) and needs no translation programs (compiler,
Assembler, Interpreter). Machine language is the language
of binary digits 0’s and 1’s(“0” means “OFF” and “1” means
“ON) that is why it is also called as binary language. It is very
difficult to write programs using 0’s and 1’s i.e. in machine
language. Thus machine language is totally machine
dependent and is efficient for computers and inefficient for
programmers.
6
Main Points of Machine
language
The first language that was invented.
It is machine dependant.
It is also called binary language.
It is the most complicated and hard language.
A program created in machine language
cannot be run on any other computer
• Machine language depends on electric pulses
(i.e on / off).
7
ASSEMBLY LANGUAGE
The computer professionals developed one step higher
language than the machine language which is called
Assembly language .The binary codes of machine language
(0’s and 1’s) were replaced by some special codes called
mnemonics. The programs in Assembly language are written
using these mnemonic codes as: ADD for addition, SUB for
subtraction MUL for multiplication
These mnemonics are understandable by the human but not
understandable by the machine. To make it understandable
for the machine, a program called assembler is developed its
function is to translate a program written in assembly
language into machine language
8
Main points of Assembly
Language
it is one step easy then machine language.
It is also called symbolic language
(abbreviation are used).
It is machine dependent.
Slow and tedious language.
Special words are used as symbols called
MNEMONICS.
A program created on one computer cannot
run on another type of computer.
9
2) High Level Language
These languages are fairly
machine independent and English like.
The programmer can understand more easily
and enable the programmer to write instructions
easily using English words and familiar
mathematical symbols such as if else, for, goto,
+,- etc.
A program written in high-level language is
translated into machine understandable form
with the help of Translation programs i.e
interpreter or compiler.
10
Main Points of High Level
Language
It is English oriented language.
It is much easy to learn.
High level program is just like giving instruction
to a person in daily life.
High level program need preprocessor to
convert the program into machine codes.
Different types of programming languages are
FORTRAN, Pascal, C and C++ etc
11
The high level languages are of two types:
•Procedural languages/Structured languages.
•OOP (Object Oriented Programming) languages
A Procedural language is that in which each statement
tells the computer to do something. Get some input and
process the input and provide the output to the user , in
simple words a program in a procedural language is a
list of instructions that’s created by a user or programmer
OOP
In this language different objects are created from each
other and then used in different functions
12
Programming Language
Characteristics
Programming languages have some
characteristics that describe how they work and
provide information about the types of computing
tasks for which they are appropriate. When you
need to select a language to use for a program,
it is useful to understand some of the general
characteristics of programming languages and
the advantages or disadvantages of these
characteristics are given as
13
Characteristics of High Level
languages
The general characteristics of ‘High Level Languages’ are as follows
Machine Independence
High-Level languages are machine independent. This is a very
valuable advantage because it means that a program written in a
high-level language can be run on many different types of
computers with very little or practically no effort.
Easy to learn and use:
These languages are very similar to the languages normally used
by us in our day-to-day life. Hence they are easy to learn and use.
14
Fewer errors
In case of high-level languages, since the programmer need not
write all the small steps carried out by the computer, he is much
less likely to make an error. The computer takes care of all the
little details, and will not introduce any error of its own unless
something breaks down. Furthermore, compilers are so designed
that they automatically catch and point out the errors made by the
programmer. Hence diagnostic errors, if any, can be easily
located and corrected by the programmer.
Lower program preparation cost
Writing program in high-level languages requires less time and
effort which ultimately leads to lower program preparation cost.
15
Better documentation
A high-level language is designed in such a way that its
instructions may be written more like the language of the problem.
Thus the statements of a program written in a high-level language
can be easily understood by a person familiar with the problem.
For the documentation of such programs, very few or practically
no separate comment statements are required.
Easier to maintain
Programs written in high-level languages are easier to maintain
than assembly language or machine language programs. This is
mainly because they are easier to understand and hence it is
easier to locate, correct, and modify instructions as and when
desired. Insertion or removal of certain instructions from a
program is also possible without any compilation. Thus, major
changes can be incorporated with very little effort.
16
Language Translator
Translators are system programs, which translate programs written
in any high or assembly language into machine language (1’s and
0’s).
Program code Language Machine code
translator
There are three types of language processors
or translators
Assembler
Compiler
Interpreter
17
Language Translators
Assembler
The software that translates and assembly code into
the computer’s machine code is called assembler
A program written by a programmer in assembly
language is called source program
After this source code has been converted into object
code
Source Program Assembler Machine code
18
Language Translators
Complier
A compiler is a computer software that translates a
whole program, called the source code at once into
machine code (object code)
Interpreter
An interpreter in another type of translator used for
translating a language program into machine code
It takes one statement of program and translates it
into a machine instruction which is immediately
executed by computer
Source Program Compiler/Interpreter Machine code
19
PROGRAM
Is a set of instructions, or a set of sequential
instructions which are given to computer to solve
a specific problem. Programs are written in
computer languages like BASIC, PASCAL,C etc
--------------
--------------
------C-------
---program- Run on computer
--------------
--------------
---------------
20
Different types of Programs
Generally there are THREE types of
Programs that’s are created in a
programming Languages
Source Programs
Object Programs
Executable Programs
21
Source & Object Programs
Source Program:-The program which is written by the
user/programmer in a computer language is called source
program.
A Program that is created by user in a high level (C/C++)
language with the extension of CPP/C.
Object program:-The program which is converted into
machine understandable code by the compiler is called
object program.
A program that is created by the language processor in the
form of codes is called Object program.
A program that is converted in to object language (Machine)
is called object program
22
Executable Program
A program that is created by language processor
to show or provide the output of a source program.
A program that is directly run or executes to
provide results of the input.
A Program (software) that’s satisfy the user
requirements or provide the solution of the user
problem
Executable program:-When source and object program
are linked that’s create a new executable program is called
exe program.
23
First.C
-------------- C Files
--------------
-Source--
---program-
--------------
First.Obj
--------------
---------------
--------------
After --------------
Compilation -Object--
---Code----
--------------
--------------
--------------- First.Exe
After --------------
Linking --------------
-Executable--
---Code-
--------------
--------------
24
---------------