Programming Lecture 1
Programming Lecture 1
Computer Programming
IT
Topics Covered
• Introduction to programming
• Flowchart
• Pseudo code
• Algorithms
Programming I BY Basha K, 2022 Programming Lecture 1 3
Introduction
• What is a computer?
What is a program?
• Computer programs, software programs, or just programs are
Conti…
• A computer program consists of two elements:
• Code – action
• Data – characteristics
Programming language
• A programming language is an artificial language that can be used
Conti…
• A main purpose of programming languages is to provide instructions
to a computer.
• Available programming languages come in a variety of forms and
types.
• Programming languages can be divided in to two major categories:
1. Low-level languages
• Machine Language
• Assembly Language
2. High-level languages
Programming I BY Basha K, 2022 Programming Lecture 1
invention of computers.
• There are three levels of programming languages. These are:
3. Debugging any set of codes is a very difficult task since it requires going
through the program instruction from the beginning to the end.
2. Assembly Language
• This is a low level of programming language which is different from the machine
language.
• That is, the instructions are not entirely in binary coded form.
• It also consists of some symbolic codes, which are easier to remember than
machine codes.
• In assembly language, memory addresses are referenced by symbols rather than
Conti..
Correspondences symbolic instructions and executable machine codes
and was created to use letters (called mnemonics) to each machine
language instructions to make it easier to remember or write.
For example:
ADD A, B – adds two numbers in memory location A and B
Conti…
• The disadvantages of assembly language are that:
written in it are:-
Easier to read and more user friendly than those written in machine
attention to the steps or procedures involved in solving the problem for which
the program is to be used to execute the problem.
• High-level language is usually broken into one or more states such as:
• Main programs, sub-programs, classes, blocks, functions, procedures, etc.
• The name given to each component differs from one language to the other.
Programming I BY Basha K, 2022 Programming Lecture 1
Conti…
• It saves much time and effort when used compared to any other
statements.
• It may require a translator before it can be understood by a computer.
• Programming languages are written and processed by the computer for the
purpose of communicating data between the human being and the computer.
Programming I BY Basha K, 2022 Programming Lecture 1
1. Translators
• A translator is a program that translates another program written in any
1. Assembler: This is a program that converts programs written in assembly or low-level language to
machine language.
Programming I BY Basha K, 2022 Programming Lecture 1
Features of Translators
programming languages
• Without them, the programs cannot be executed.
Programming I BY Basha K, 2022 Programming Lecture 1
that a:-
A compiler converts the entire source program into object code before
Programming paradigms
order of execution from the first statement to the second and so forth.
Procedural programming specifies a list of operations that the program must complete to
By splitting the programmatic tasks into small pieces, procedural programming allows a
of objects, which are data structures that contains data in the form of fields,
known as attributes and code in the form of procedures known as method.
This pairing of a piece of data with the operations that can be performed on it is
known as an object.
A program thus becomes a collection of cooperating objects, rather than a list of
instructions.
Objects can store state information and interact with other objects, but generally
• The second introduces the means by which programmers communicate those procedures to the
Conti…
There are system analysis and design tools, particularly flowchart and structure
chart, that can be used to define the problem in terms of the steps to its solution.
The programmer uses programming language to communicate the logic of the
are to be used, the desired result, and the procedure to be used to produce the
result.
The procedure, or solution, selected is referred to as an algorithm.
terminate and describe how the data is to be processed to produce the desired
outputs.
Programming I BY Basha K, 2022 Programming Lecture 1
Conti…
Algorithms
• Correctness: it must be correct and must solve the problem for which it is
designed.
• Finiteness: it must execute its steps and terminate in finite time.
• Algorithms are usually represented in pseudo code or by a flow chart.
Programming I BY Basha K, 2022 Programming Lecture 1 26
Pseudocodes
• is English like language for representing the solution to a problem.
flow chart) is the first step in the process of planning the solution to a problem.
• Pseudo code is a compact and informal high-level description of a computer
executable program.
• The purpose of using pseudocode is that it may be easier for humans to read
Pseudocode
• As the name suggests, pseudocode generally does not actually obey the syntax rules
• You must first understand the program specifications, of course, Then you need to
• You must break the main tasks that must be accomplished into smaller ones in order
a program's development.
Programming I BY Basha K, 2022 Programming Lecture 1 28
Example:
• Original Program Specification:
• Write a program that obtains two integer numbers from the user. Print out the sum of those
numbers.
• Pseudo code:
• Prompt the user to enter the first integer
• Prompt the user to enter a second integer
• Compute the sum of the two user inputs
• Display an output prompt that explains the answer as the sum
• Display the result
• Pseudo code:
• If student's grade is greater than or equal to 60
• Print "passed"
• else
• Print "failed"
Programming I BY Basha K, 2022 Programming Lecture 1 29
Flowcharts
• A flowchart is a graphical way of representing the solution to a problem
processes.
Programming I BY Basha K, 2022 Programming Lecture 1 30
Conti…
Figure 2: flowchart symbols adopted by the American National Standards Institute (ANSI)
Programming I BY Basha K, 2022 Programming Lecture 1 32
Example 1:
• Add A and B
Example 2
• Write a pseudo code and draw a flow chart to check a number is negative or
not.
Algorithm description.
1. Start
2. Read a number x
3. If x is less than zero then
Write “Negative”
Else
Write “Not Negative”
4. stop
Programming I BY Basha K, 2022 Programming Lecture 1 35
Programming I BY Basha K, 2022 Programming Lecture 1 36
Example 3
1. Start
2. Initialize Sum to 0 and Counter to 1
2.1 If the Counter is less than or equal to 50
• Add Counter to Sum
• Increase Counter by 1
• Repeat step 2.1
2.2 Else
• Exit Loop
3.Write Sum
4. Stop
Programming I BY Basha K, 2022 Programming Lecture 1 37
Programming I BY Basha K, 2022 Programming Lecture 1 38
Exercise:
1. Write an algorithm description and draw a flow chart to
check a number is even or odd.
End of Lecture 1