Lecture No. 01 [Computer Programming]
Lecture No. 01 [Computer Programming]
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Topics:
Computer programming
Why do we need programming?
What Computer Programmers Do?
Program Development Process
Algorithms
Structured Programming
Advantages of Structured Programming
Disadvantages of Structured Programming
Programming Languages
Types of Programming Languages
Low Level Languages
Machine Language
Assembly Languages
High-level Languages
Difference between Procedural and Non-Procedural Languages
Difference between Low-Level and High-Level Languages
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Computer Programming:
A computer program is a set of step-by-step instructions that directs the computer to do
the task and produce the results.
A computer program is also called a computer software, which can range from two lines to
millions of lines of instructions.
A set of rules that provides a way of telling a computer what operations to perform is called
a programming language.
With the help of programming, only machines can understand user-given commands.
Computer programming will impact the future by creating even more automated processes
requiring less human interaction.
That is, the programmer prepares the instructions of a computer program and runs those
instructions on the computer, tests the program to see if it is working properly, and makes
corrections to the program.
Someone who can write computer programs or in other words, someone who can do computer
programming is called a Computer Programmer.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Program Development Process:
A programmer has to go through the following stages to develop a computer program.
There are five main ingredients in the programming process:
Defining and Analyzing Problem.
Designing the Algorithm (Planning the Solution).
Coding or Writing the Program.
Testing the Program
Final Documentation (Documenting the Program)
Structured Programming:
Structured Programming is a type of programming that generally converts large or complex
programs into more manageable and small pieces of code.
These small pieces of codes are usually known as functions, procedures, modules
or sub-programs of large complex programs. Each function/module performs a specific task
and can be executed when the main program calls it.
It is also known as modular programming.
Structured Programming is an easy and simple technique for writing programs.
It makes programs easier to write, check, read and modify.
C language and Pascal are some examples of Structured Programming.
Structured Programming was first suggested by Corrado Bohm and Guiseppe Jacopini.
Sequence Structure: Executes statements one after the other in a linear fashion.
Selective Structure (or Decision): Uses conditional statements (e.g., if, else) to choose different
execution paths based on certain conditions.
Iterative Structure (or Looping): Repeats a block of code multiple times using loops (e.g., for, while).
Procedural Programming: Defines modules as procedures or functions that are called with a set
of parameters to perform a task.
Object-Oriented Programming (OOP): Defines a program as a set of objects or resources to
which commands are sent.
Model-based Programming: The most common example of this is database query languages.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Advantages of Structured Programming:
Easier to read and understand.
Reusability (of code).
Easier to Code.
Easier to Modify.
Easier to Maintain.
Easier to Debug.
Unstructured Programming:
A programming language in which the entire logic of the program is written as a single
continuous (nonstop or unbroken) block is called Unstructured Programming.
Program written by following this language is very difficult to modify and to debug.
Unstructured Programming is a type of programming that generally executes in sequential
order i.e., these programs just not jumped from any line of code and each line gets executed
sequentially.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Structured Programming avoids code duplication while unstructured programming can have
code duplication.
It is easy to do testing and debugging in structured programming while it is hard to do testing
and debugging in unstructured programming.
Programming Languages:
A set of words, symbols and codes used to write programs is called programing language.
Programming languages are said to be "lower" or "higher," depending on how close they are
to the language the computer itself uses (0s and 1s = low) or to the language people use (more
English-like-high).
Machine language:
A type of language in which instructions are written in binary form (0, 1) is called machine
language.
It is the only language that is directly understood by the computer.
It is the fundamental language of the computer.
Programs written in machine language can be executed very fast by the computer.
Programs written in machine language are machine dependent so, every type computer has its
own machine language.
Machine language is difficult to understand. Writing and modifying program in machine
language takes a lot of time.
Machine language is also known as First Generation Language (1GL).
The lowest level of language (machine language) represents data and program instructions as
1s and 0s-binary digits corresponding to the on and off electrical states in the computer.
Primitive by today's standards, the programs were not convenient for people to read and use.
The computer industry quickly moved to develop assembly languages.
Assembly Language:
Assembly language is a low-level language.
It is one step higher than machine language.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
In assembly language, symbols are used instead of binary code. These symbols are called
mnemonics.
For example, SUB instruction is used to subtract two numbers, A for Add, C for Compare, MP
for Multiply, STO for storing information in memory, and so on.
Assembly language is also called Symbolic Language.
Programs written in assembly language are easier to write and modify than machine language.
Assembly language is mostly used for writing system software.
Assembly language is also known as Second Generation Language (2GL).
Today, assembly languages are considered very low level-that is, they are not as convenient
for people to use as more recent languages.
However, they were considered a great leap (jump) forward at the time when they were
developed.
High-Level Languages:
The first widespread use of high-level languages in the early 1960s transformed programming
into something quite different from what it had been.
A type of language that is close to human languages is called High Level Language.
Hagh level languages are easy to understand.
Instructions of these languages are written in English like words such as input and print etc.
A program written in high level language is easier to write and modify.
Procedural Languages:
Procedural languages are also known as Third Generation Languages (3GL).
In these languages, a program is a predefined set of instructions.
Computer executes these instructions in the same sequence in which the instructions are
written.
Each instruction in this language tells the computer what to do and how to do.
Some most popular procedural languages are: BASIC, FORTRAN, COBOL, PASCAL, and C.
Non-Procedural Languages:
Non-Procedural languages are also known as Forth Generation Languages (4GL).
In non-procedural languages, user only needs to tell the computer “What to do” not “how to do”.
An important advantage of non-procedural languages is that they can be used by non-technical
user to perform a specific task.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
These languages accelerate program process and reduce coding errors.
4GL are normally used in database applications and report generation.
Some important non-procedural languages are as follows:
SQL
RPG
PHP etc.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.