Chapter 1 (Autosaved) 122222
Chapter 1 (Autosaved) 122222
Chapter One
Introduction to Programming
04/23/2025 1
Outline
Introduction to Computer and computer
programming
Programming languages
Programming paradigm
Problem solving techniques
SDLC
04/23/2025 2
Introduction to programming
Computer ?
an electronic device that accepts data, performs computations,
and makes logical decisions according to instructions that have
been given to it
then produces meaningful information in a form that is useful
to the user
Computer programs ?
Sets of instructions that control a computer’s processing of data
the instructions that tells the computer what to do
Computer programming ?
is the process of writing, testing, debugging / troubleshooting,
and maintaining the source code of computer programs
04/23/2025 3
Introduction to programming
Computer programs (also known as source code) is often
written by professionals known as Computer Programmers
A computer program usually consists of two elements:
Data – characteristics
Code – action
Source code is written in one of programming languages
04/23/2025 4
Introduction to programming
What is Programming Language?
Is an artificial language that can be used to control the behavior
of a computer
defined by
Syntactic - describes the possible combinations of symbols
that form a syntactically correct program
Semantic - The meaning given to a combination of symbols
computers do exactly what they are told to do
04/23/2025 5
The syntax of a programming language
describes which strings of of characters
comprise a valid program.
The semantics of a programming
language describes what syntactically
valid programs mean, what they do. In the
larger world of linguistics, syntax is about
the form of language, semantics about
meaning.
04/23/2025 6
There are two types of computer languages:
Low-Level Languages: These languages give instructions to a computer
in a way that is easily understood by the hardware of the computer. These
languages are easier for a computer to understand but difficult for a
human understanding. This language is machine-dependent or specific to
a given computer. Two low-level languages are Machine Language and
Assembly Language.
04/23/2025 7
Machine language
i)Code is written in binary language.
(ii) Binary codes for machine instructions can run
directly on hardware.
(iii) No extra tool required for code conversion.
(iv) Machine language depends upon the processor of
a computer. So, for a different processor, machine
language codes will differ.
Discuss the feature of assembly language.
Answer:
(i) Uses mnemonic codes to represent machine instructions.
(ii) Low-level language.
(iii) Cannot run directly on hardware requires Assembler software that
converts it to machine code first.
(iv) Varies from one processor to another, i.e, different assembly
codes for different processors
04/23/2025 8
Introduction to programming
Machine language
machine is short for computing machine (i.e., computer)
computer’s native language, sequence of zeroes and ones
(binary)
different computers understand different sequences
hard for humans to understand: 01010001…
low level: language(assembly language)
mnemonics for machine language
each instruction is minimal
still hard for humans to understand: ADD d0,d2
High-level languages
high level: each instruction composed of many low-level
instructions
closer to English easier to read and understand:
FORTRAN, Pascal, BASIC, C, C++,04/23/2025
Java, COBOL, etc. 9
Higher level languages are simple languages that use
English and mathematical symbols like +, -, %, / etc. for its
program construction.
You should know that any higher level language has to be
converted to machine language for the computer to
understand.
Higher level languages are problem-oriented languages
because the instructions are suitable for solving a particular
problem
feature of a high-level language.
Answer:
(i) Use English like words.
(ii) Cannot run directly on computer hardware require a translator
software to translate high-level instruction code to machine
language code.
(ii) Easier to read and understand for us humans (near to humans
hence High Level).
(iv) Require coding for the detailed procedure of how the task is to
be done. 04/23/2025 10
or example COBOL (Common Business
Oriented Language) is mostly suitable for
business oriented
language where there is very little
processing and huge output. There are
mathematical oriented languages like
FORTRAN (Formula Translation) and BASIC
(Beginners All-purpose Symbolic
Instruction Code) where very large
processing is required
04/23/2025 11
Three types of translator
Compiler
Interpreter
Assembler
Compilers, interpreters, translate programs written in high-level languages
into machine code that a computer understands and assemblers translate
programs written in low-level or assembly language into machine code. In
the compilation process, there are several stages. To help programmers write
error-free code, tools are available.
Assembly language is machine-dependent, yet mnemonics used
to represent instructions in it are not directly understandable by
machine and high-Level language is machine-independent.
A computer understands instructions in machine code, i.e. in the
form of 0s and 1s. It is a tedious task to write a computer program
directly in machine code.
04/23/2025 12
Interpreting Vs Compiling Program
Each type of computer only “understands” its own machine
language (zeroes and ones)
Thus we must translate from High-level language to machine
language
◦ a team of experts programs a translator, called a “compiler”
which translates entirety of a High-level language program to an
executable file in computer’s native machine language.
Running :
◦ compilation: Your program executable
◦ execution: run executable
machine executes your program by “running” each machine
language instruction in the executable file
04/23/2025 13
Compiler …It is a program translator that
translates the instruction of a higher level
language to machine language.
It is called compiler because it compiles machine
language instructions for every program
instructions of higher level language.Thus
compiler is a program translator like assembler
but more sophisticated.
It scans the entire program first and
then translates it into machine code
04/23/2025 14
source code vs object code
object code is the machine-readable code that is generated by the compiler,
and it serves as an intermediate step between the source code and the final
executable code. Object code files are specific to the target architecture and
operating system and are typically stored in a binary file format .
The programs written by the programmer in higher level language is called
source program. After this program is
converted to machine languages by the compiler it is called object program.
04/23/2025 15
Interpreter
An interpreter is another type of program
translator used for translating higher level
language into machine language.
It takes one statement of higher level
languages, translate it into machine
language and immediately
execute it.
Translation and execution are carried out
for each statement.
It differs from compiler, which translate
the entire source program into machine
code and does involve in its execution.
04/23/2025 16
Interpreting Vs Compiling Program
An alternative to compiling your program is to interpret your
program
◦ each line of your program is translated into machine language
and immediately executed
04/23/2025 17
Programming paradigm
A programming paradigm is a fundamental style of
programming
Unstructured Programming
Procedural programming .
Structured Programming
Object Oriented Programming
04/23/2025 18
Unstructured Programming
consisting only of one large (usually main) program
“main program”' stands for a sequence of commands or
statements
◦ data is global throughout the whole program
disadvantages
◦ Complex
◦ if the same statement sequence is needed at different
locations within the program, the sequence must be copied
04/23/2025 19
Procedural programming
based upon the concept of procedure call
A procedure call is used to invoke the procedure
Procedures (routines, subroutines, methods, functions) simply
contain a series of computational steps to be carried out to solve a
problem
04/23/2025 20
Procedural programming
• We have a single program, which is divided into small pieces
called procedures
• Advantage
• to re-use the same code at different places in the program
without copying it
• easier way to keep track of program flow
• Example
• FORTRAN, ADA 04/23/2025 21
Structured Programming
is a subset of procedural programming (also known as modular
programming)
procedures of a common functionality are grouped together into
separate modules
Each module can have its own data
◦ allows each module to manage an internal state which is
modified by calls to procedures of this module
top-down design model
◦ map out the overall program structure into separate subsections
Example
◦ PASCAL, C
04/23/2025 22
Structured Programming
Advantage
◦ Reuse
◦ Easier to understand and modify
04/23/2025 23
Object Oriented Programming
Is a method of implementation in which programs are organized
as cooperative collections of objects
Data and operations are grouped together
Each object is capable of receiving messages, processing data,
and sending messages to other objects
Modeling of the domain as objects so that the implementation
naturally reflects the problem at hand.
04/23/2025 24
Problem solving Techniques
Computer solves varieties of problems that can be expressed in
a finite number of steps
In computer programming two facts :
Defining the problem and logical procedures to follow in
solving it.
Introducing the means by which programmers
communicate those procedures to the computer system so
that it can be executed.
04/23/2025 25
Problem solving Techniques
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 solution to the computer.
An algorithm is defined as a step-by-step sequence of
instructions that must terminate and describe how the data is
to be processed to produce the desired outputs.
Simply, algorithm is a sequence of instructions
04/23/2025 26
Problem solving Techniques
programs could be written in terms of 3 structures:
◦ Sequence – which instruction should be done next?
◦ Selection – select between options
◦ Repetition – repeat an action while a given condition stays
true
An algorithm can be represented as
◦ Flowchart
◦ Pseudo code
◦ Structured chart
04/23/2025 27
Pseudo code
is an artificial and informal language that helps programmers
develop algorithms
a shorthand notation for programming which uses a combination
of informal programming structures and verbal descriptions of
code.
In general, pseudocode is used to outline a program before
translating it into proper syntax.
04/23/2025 28
Pseudo code
Example-1:
◦ Write a program that prints “passed” when the student
grade is greater than 60 and “failed” otherwise.
Solution:-
If student's grade is greater than or equal to 60
◦ Print "passed"
else
◦ Print "failed“
04/23/2025 29
Pseudo code
Example-2:
◦Pseudo-code the task of computing the final price of an item after
figuring in sales tax. Note the three types of instructions: input
(get), process/calculate (=) and output (display)
1. get price of item
2. get sales tax rate
3. sales tax = price of item times sales tax rate
4. final prince = price of item plus sales tax
5. display final price
6. stop 04/23/2025 30
Pseudo code
Example-3:
Write a program that obtains two integer numbers from the
user. It will print out the sum of those numbers.
1. Prompt the user to enter the first integer
2.Prompt the user to enter a second integer
3.Compute the sum of the two user inputs
4.Display an output prompt that explains the answer as the
sum
5.Display the result
04/23/2025 31
Flow Chart
A graphic representation of an algorithm,
often used in the design phase of programming to work out the
logical flow of a program
04/23/2025 32
Flow Chart
Flowchart Symbol
04/23/2025 33
Flow Chart
Example 1:
• Draw flow chart of an algorithm to add two numbers and
display their result.
Algorithm description
1. Read the two numbers (A and B)
2. Add A and B
3. Assign the sum of A and B to C
4. Display the result ( c)
04/23/2025 34
Flow Chart
Flow Chat is :
Start
Read A, B
C= A+B
Print C
End
04/23/2025 35
Flow Chart
Example 2:
Write an algorithm description and draw a flow chart to check
a number is negative or not.
Algorithm description
1. Read a number x
2. If x is less than zero write a message negative else write a
message not negative
04/23/2025 36
Flow Chart
Flow Char is :
04/23/2025 37
Write an algorithm that reads two values,
determines the largest value and prints the
largest value with an identifying message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
endif
Step 3: Print “The largest value is”, MAX
START
Input
VALUE1,VALUE2
Y is
N
VALUE1>VALUE2
Print
“The largest value is”,
MAX
STOP
Write an algorithm to determine a student’s final
grade and indicate whether it is passing or failing.
The final grade is calculated as the average of four
marks.
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
04/23/2025 40
04/23/2025 41
example 3
Write an algorithm and draw a flowchart that will
read
the two sides of a rectangle and calculate its
area.
Pseudocode
Input the width (W) and Length (L) of a
rectangle
Calculate the area (A) by multiplying L with W
Print A
04/23/2025 42
04/23/2025 43
Write an algorithm to find the sum and average of 3
numbers
Step1; start
Step2: read a,b,c [input 3 numbers]
Step3: sum a+b+c [find sum]
Step4: avgsum/3 [find average]
Step5: Print sum, avg [output result]
Step6: stop
04/23/2025 44
04/23/2025 45
Flow Chart
Some times there are conditions in which it is necessary to
execute a group of statements repeatedly. Until some
condition is satisfied. This condition is called a loop.
Loop is a sequence of instructions, which is repeated until
some specific condition occurs.
A loop normally consists of four parts.
04/23/2025 46
Flow Chart
A loop normally consists of four parts. These are:
◦ Initialization: - Setting of variables of the computation to
their initial values and setting the counter for determining to
exit from the loop.
◦ Computation: - Processing
◦ Test: - Every loop must have some way of exiting from it or
else the program would endlessly remain in a loop.
◦ Increment: - Re-initialization of the loop for the next loop.
04/23/2025 47
Flow Chart
Example -3:
Write the algorithmic description and draw a flow chart to
find the following sum.
Sum = 1+2+3+…. + 50
Algorithm description
1. Initialize sum to 0 and counter to 1
1.1. If the counter is less than or equal to 50
• Add counter to sum
• Increase counter by 1
Repeat step 1.1
1.2. Else
• Exit
2. Write sum 04/23/2025 48
Flow Chart
Flow Char is :
04/23/2025 49
Structure Chart
depicts the logical functions to the solution of the problem
using a chart.
It provides an overview that confirms the solution to the
problem without excessive consideration to detail.
It is high-level in nature.
04/23/2025 50
Structure Chart
Example-1:
Write a program that asks the user to enter a temperature
reading in centigrade and then prints the equivalent
Fahrenheit value.
Input Process Output
Centigrade Prompt for centigrade value Fahrenheit
Read centigrade value
Compute Fahrenheit value
Display Fahrenheit value
04/23/2025 51
System Development Life
Cycle(SDLC)
is a conceptual model used in project management that
describes the stages involved in a computer system
development project from an initial feasibility study through
maintenance of the completed application.
04/23/2025 52
System Development Life
Cycle(SDLC)
The phases of SDLC are :
Feasibility study :
Requirements analysis
Designing solution
Testing designed solution
Testing
Implementation
04/23/2025 53
System Development Life Cycle
Feasibility study : The first step is to identify a need for the
new system.
a. Organizational Feasibility
How well the proposed system supports the strategic
objectives of the organization.
b. Economic Feasibility
Cost savings
Increased revenue
Decreased investment
Increased profits 04/23/2025 54
System Development Life Cycle
c. Technical Feasibility
Hardware, software, and network capability, reliability,
and availability
d. Operational Feasibility
End user acceptance
Management support
Customer, supplier, and government requirements
04/23/2025 55
System Development Life Cycle
Requirements analysis : is the process of analyzing the
information needs of the end users, the organizational
environment, and any system presently being used, developing
the functional requirements of a system that can meet the
needs of the users.
04/23/2025 56
System Development Life Cycle
Designing solution:
After the requirements have been determined, the necessary
specifications for the hardware, software, people, and data
resources, and the information products that will satisfy the
functional requirements of the proposed system can be
determined.
The design will serve as a blueprint for the system and helps
detect problems before these errors or problems are built into
the final system.
04/23/2025 57
System Development Life Cycle
Implementation
The real code is written here. Systems implementation is the
construction of the new system and its delivery into
production or day-to-day operation.
04/23/2025 58
System Development Life Cycle
Testing
◦ Unit Testing
◦ Integrating Testing
◦ System Testing
Maintenance
What happens during the rest of the software's life: changes,
correction, additions, and moves to a different computing
platform and more.
This, the least exciting and perhaps most important step of all,
goes on seemingly forever.
04/23/2025 59