0% found this document useful (0 votes)
4 views

Lecture No. 01 [Computer Programming]

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture No. 01 [Computer Programming]

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Discipline: BS (CS) 1st Semester

Subject: Programming Fundamentals


Week No.: 01 [Introduction to Computer Programming]
Prepared by: ARSHAD IQBAL, Lecturer (Computer Science),
Computer Science Department, CECOS University of IT & Emerging
Sciences, Peshawar

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 a sequence of instructions written using a computer programming


language to perform a specified task by the computer.

 A computer program is also called a computer software, which can range from two lines to
millions of lines of instructions.

 Computer program instructions are also called Program Source Code.

 The act of writing computer programs is called Computer Programming/Program Codding.

 Computer programming is the process of designing and developing various computer


programs to complete specific tasks.

 The whole procedure of writing a computer program is called Computer Programming.

 A set of rules that provides a way of telling a computer what operations to perform is called
a programming language.

Why do we need programming?


 The main goal of programming is to make tasks easier because if we write a program to
perform a task for one time, then it can be reused in many similar situations, saving time.

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

 For example, Banking from any location is possible only by programming.

What Computer Programmers Do?


 In general, the programmer's job is to convert problem solutions into instructions for
the computer.

 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)

Defining and Analyzing Problem:


 In this step, a programmer studies the problem. He decides the best way to solve the problem.
 Studying a problem is necessary because it helps a programmer to decides about the following things:
 The facts and figures which are necessary for developing the program.
 The way in which the program will be designed.
 The language in which the program will be most suitable.
 What is the desired output etc.

Designing the Algorithm (Planning the Solution):


 An algorithm is a sequence of steps that must be carried out before a programmer starts
preparing his program.
 The programmer designs an algorithm to make easier to solve the problem.

Coding or Writing the Program:


 The process of writing a program is a very important step in program development.
 In this step, an algorithm is converted into program.
 The program consists of different steps given in the algorithm.
 A large number of programming languages are available to write programs.
 A programmer selects programming language according to the nature of problem.

Testing the Program:


 A program must be tested in the process of program development.
 This process verifies the accuracy of a program.
 The program is tested by executing it again and again.
 Different values are given as input and output is checked. The program may not give required
results if it contains any error. The error must be detected and corrected if the output is not
correct.
 All bugs in the program are detected and removed during program testing.
 It ensures that the program gives desired results and the problem is solved correctly.

Final Documentation (Documenting the Program):


 When the program is finalized, its documentation is prepared.
 Final documentation is provided to the user.
 It guides the user how to use the program in the most efficient way.
 Another purpose of documentation is to allow some other programmer to modify the code and
if necessary.
 Documentation should be done in each step during development of a program.
Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.
Algorithms:
 From programming point of view, an algorithm is a step-by-step procedure to solve
any problem.
 An algorithm is an effective method expressed as a finite set of well-defined instructions.
 Thus, a computer programmer lists down all the steps required to resolve a problem before
writing the actual code.
 Following is a simple example of an algorithm to find out the largest number from a given list
of numbers:
Step01: Get a list of numbers L1, L2, L3...LN.
Step02: Assume L1 is the largest, Largest = L1.
Step03: Take next number Li from the list and do the following.
Step04: If Largest is less than Li then Largest = Li.
Step05: If Li is last number from the list, then.
Step06: Print value stored in Largest and come out.
Step07: Else repeat same process starting from step 3.

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.

 The structured program mainly consists of three types of instructions:


 Sequence Structure
 Selective (Decision) Structure
 Iterative (Looping) Structure

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

Types of Structured Programming:


There are three types/categories of Structured Programming:

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.

Disadvantages of Structured Programming:


 Since it is Machine-Independent, so it takes time to convert into machine code.
 The converted machine code is not the same as for assembly language.
 The program depends upon changeable factors like data-types. Therefore, it needs to be
updated with the need on the go.
 Usually, the development in this approach takes longer time as it is language-dependent.
Whereas in the case of assembly language, the development takes lesser time as it is fixed for
the machine.

Why C is called a structured programming language?


 C is a structured programming language because it divides a large problem into smaller
modules called functions or procedures.
 A collection of such functions constitutes (creates) the program that solves the entire problem.

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.

Difference between Structured Programming and Unstructured Programming:


 Structured Programming is a programming paradigm (model) which divides the code into
modules or function while unstructured programming is the paradigm in which the code is
considered as one single block.
 Structured based programs are easy to read while unstructured based programs are hard to
read.
 Structured Programming is to make the code more efficient and easier to understand while
unstructured programming is just the program to solve the problem.
 Structured Programming is easier because of modules while unstructured programming is
harder when comparing with the structured programming.
 Structured Programming can be used for small and medium scale projects while unstructured
programming is not applicable for medium and complex projects.
 It is easy to do changes in structured programming while it is hard to do modifications in
unstructured programming.
 Structured programming uses many data types while unstructured programming has a limited
number of data types.

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

 There are three types of Programming Languages:


 Low Level Languages
 Machine language
 Assembly language
 High-level languages

Low Level Languages:


 These languages are near to computer hardware and far from human languages.
 Computer can understand these languages easily. Writing a program in low level languages
requires a deep knowledge of the internal structure of computer hardware.

 There are two low level languages as follows:


 Machine Language
 Assembly Language

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.

 High level languages are further divided into following categories:


 Procedural Languages
 Object Oriented Languages
 Non-Procedural Languages

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.

Object Oriented Languages:


 OOP is a technique in which programs are written on the basis of objects. An object is
a collection of data and functions. Object may represent a person, thing or place in real world.
 In OOP, data and all possible functions are grouped together.
 Object oriented programs are easier to learn and modify.
 C++ and Java are popular object-oriented languages.

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.

Difference between Procedural and Non-Procedural Languages:

Procedural Languages/3GL Non-Procedural Languages/4GL


1. Procedural Language tells the computer Non- Procedural Language tells the computer
what to do and how to do. what to do, not how to do.
2. It is difficult to learn. it is easy to learn.
3. It is difficult to debug. it is easy to debut.
4. It requires large number of procedurals it requires a few non-procedural instructions.
instructions.
5. It is normally used by professional it can be used by professional and non-technical users.
programmers.
6. It is typically file-oriented. it is typically database-oriented.
7. Procedural Language provides many Non- Procedural Language provides less
programming capabilities. programming capabilities.

Difference between Low-Level and High-Level Languages:

High-Level Languages Low-Level Languages


1. High-level languages are easy to learn. Low-level languages are difficult to learn.
2. High-level languages are near to human languages. Low-level languages are far from
human languages.
3. Translator is required. No translator is required.
4. Programs in high-level languages are slow Programs in low-level languages are fast
in execution. in execution.
5. Programs in high-level languages are easy to modify. Programs in low-level languages are
difficult to modify.
6. High-level languages do not provide much facility Low-level languages provide facility
to write at hardware level. to write programs at hardware level.
7. Deep knowledge of hardware is not required to Deep knowledge of hardware is
write programs. required to write programs.
8. These languages are normally used to write These languages are normally used to
application programs. write hardware programs.

Prepared by: ARSHAD IQBAL, Lecturer (CS), Computer Science Department, CECOS University of IT & Emerging Sciences, Peshawar.

You might also like