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

Chapter 1 Intoduction to Programming Language (1)

Chapter Four introduces programming, defining computers as devices that process data and solve problems across various fields. It explains the nature of computer programs, programming languages, and categorizes them into low-level, assembly, and high-level languages, along with their paradigms such as procedural and object-oriented programming. The chapter also outlines the Software Development Life Cycle (SDLC) and the importance of algorithms, pseudocode, and flowcharts in programming.

Uploaded by

mamushwondu21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Chapter 1 Intoduction to Programming Language (1)

Chapter Four introduces programming, defining computers as devices that process data and solve problems across various fields. It explains the nature of computer programs, programming languages, and categorizes them into low-level, assembly, and high-level languages, along with their paradigms such as procedural and object-oriented programming. The chapter also outlines the Software Development Life Cycle (SDLC) and the importance of algorithms, pseudocode, and flowcharts in programming.

Uploaded by

mamushwondu21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Chapter Four

4.1 Introduction to programming


 A Computer is an electronic device that accepts data, performs computations, and makes
logical decisions according to instructions that have been given to it; then it produces a
meaningful information in a form that is useful to the user.
 In current world, computers are almost used in all stage of life for different purposes.

 They have been deployed to solve different real life problems, from the simplest game
playing up to the complex nuclear energy production.
 Nowadays, Computers are used almost everywhere.

 Most of the areas have already started working with the help of computers such as
scientific researches, Banking, Airways, communication, businesses, Education, Industries,
engineering, hospital and so on. Any tools the used by engineers is developed by
programming language.
The terms computer programs, software programs, or just
programs are the instructions that tells the computer what to do.
 computer programs does nothing unless its instructions are
executed by a CPU.
Computer programming (often shortened to programming or
coding) is the process of writing, testing, debugging/
troubleshooting, and maintaining the source code of computer
programs.
Writing computer programs means writing instructions, that will
make the computer follow and run a program based on those
instructions.
• Computer programs (also know as source code) is often written by
professionals known as Computer Programmers (simply
programmers).
• Source code is written in one of programming languages.
• A programming language is an artificial language that can be used
to control the behavior of a machine, particularly a computer.
Programming languages, like natural language, are defined by
syntactic and semantic rules which describe their structure and
meaning respectively.
• The syntax of a language describes the possible combinations of
symbols that form a syntactically correct program. The meaning
given to a combination of symbols is handled by semantics
• A main purpose of programming languages is to provide/run
instructions to a computer.
• Computers do exactly what they are told to do, and cannot
understand the code the programmer "intended" to write.
• Computer languages have relatively few, exactly defined, rules for
composition of programs, and strictly controlled vocabularies in
which unknown words must be defined before they can be used.
 Programming languages can be divided in to three major categories:
low-level, Assembly language and high-level languages.
1. Low-level languages
 Computers only understand one language and that is binary language or the language of 1s and
0s. Binary language is also known as machine language, one of low-level languages
 Although the computer easily understood these programs, it proved too
difficult for human being to remember all instructions.
 Language was developed, which were easier to learn and understand.
2. Assembly language 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
 The assembly language must be translated to machine code by a separate
program called assembler.
 The machine instruction created by the assembler from the original program
(source code) is called object code.
3. High-level languages
High-level languages are more English-like, it easier for programmers
(human).
• High-level languages also require translation to machine language before
execution. This translation is accomplished by two ways.
 Compilers translate the entire source code program before execution.
Interpreters translate source code programs one line at a time. Interpreters are
more interactive than compilers
some examples of high-level languages are FORTRAN (FORmula
TRANslator), BASIC (Bingers All Purpose Symbolic Instruction Code),
PASCAL, C, C++, Java e.t.c
• Every language has its strengths and weaknesses.
• For example, FORTRAN is a particularly good language for processing numerical
data, but it does not lend itself very well to organizing large programs. Pascal is very
good for writing well-structured and readable programs, but it is not as flexible as the
C programming language. C++ embodies powerful object-oriented features
Programming Paradigm
• Another most fundamental ways programming languages are
characterized (categorized) is by programming paradigm. A
programming paradigm provides the programmer's view of code
execution. The most influential paradigms are examined in the next
three sections, in approximate chronological order.
• Procedural Programming Languages
• Object-Oriented Programming Languages
• Procedural programming specifies a list of operations that the program must complete
to reach the desired state.
• Each program has a starting state, a list of operations to complete, and an ending point.
This approach is also known as imperative programming. Integral to the idea of
procedural programming is the concept of a procedure call.
• Procedures, also known as functions, subroutines, or methods, are small sections of
code that perform a particular function.
• A procedure is effectively a list of computations to be carried out. Procedural
programming can be compared to unstructured programming, where all of the code
resides in a single large block.
• By splitting the programmatic tasks into small pieces, procedural programming allows a
section of code to be re-used in the program without making multiple copies. It also
makes it easier for programmers to understand and maintain program structure.
• Two of the most popular procedural programming languages are FORTRAN and BASIC.
Object-Oriented Programming
Languages
• Object-oriented programming is one the newest and most powerful
paradigms. In object- oriented programs, the designer specifies both
the data structures and the types of operations that can be applied to
those data structures.
• 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 each object has a distinct, limited role.
Software Development Life Cycle (SDLC)
• The Systems Development Life Cycle (SDLC) is a conceptual model used in
project management that describes the stages involved in system
development project.
• In general, the SDLC includes the following phases:
1. Feasibility Study: in this phase, the problem is identified precisely and
completely, i.e. understanding exactly what the problem is, what is
needed to solve it? What are the constraints and special conditions?
The feasibility study is used to determine if the project should get the go-
ahead. If the project is to proceed, the feasibility study will produce a
project plan and budget estimates for the future stages of development.
2. Requirement Analysis: Analysis gathers the requirements for the system. This
stage requires analysis of the data and procedures needed to achieve the
desired result. In this phase, the developer needs to develop various solutions
to solve the given problem..
3. Design: once the requirements of the program are defined, the next stage is to
design a solution to solve the problems. This stage is also called
Algorithm/Program design. In general, this phase focuses on:
• High Level Design: i.e. what programs are needed and how are they going to
interact.
• Low level Design: i.e. how the individual programs are going to work.
• Interface Design: i.e. what is the interface going to look like.
• Data Design: i.e. what data will be required?
Cont.…
4. Testing the Algorithm (Design): Before converting the algorithms into actual
code, it should be checked accuracy. The main purpose of checking algorithm is
to identify major logical errors at early stages, because logical errors are often
difficult to detect and correct at later stages. The testing also ensures that the
algorithm is a ‘true’ one and it should work for any data
5. Implementation (Coding): In this phase the designs are translated into code.
Computer programs are written using a conventional programming language.
Programming tools like Compilers, Interpreters, and Debuggers are used to
generate the code. Different high level programming languages like C, C++,,
and Java are used for coding.
6. Testing: once the code is generated (implemented), the software program
testing is begins. There are three different testing methodologies. These are:
1.3 Problem solving Techniques

In computer programming two facts are given more weight:


• The first part focuses on defining the problem and logical procedures to
follow in solving it(SDLC).
• The second introduces the means by which programmers communicate
those procedures to the computer system so that it can be executed.
• There are system analysis and design used to define the problem in terms
of the steps to its solution. Like as flowchart and structure chart.
• Before a program is written, the programmer must clearly understand what
data are to be used, the desired result, and the procedure to be used to
produce the result.
• 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.
Algorithm
• Algorithms are one of the most basic tools that are used to develop a solving
logic for the problems.
• An Algorithm can be also defined as, a finite sequence of explicit instructions
that, when provided with a set of input values, produces an output and then
terminates.
• An algorithm must satisfy the following requirements:
• Unambiguousness: i.e. it must not be ambiguous. Every step in an
algorithm must be clear as to what it is supposed to do and how many
times it is expected to be executed.
• Generality: i.e. it should have to be general.
• 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.
• Efficiencies: it must be efficient with respect to time and space.
• Algorithms are usually represented in pseudo code or by a flow chart.
Simply, algorithm is a sequence of instructions.
Algorithms are a fundamental part of computing. There are three commonly
used tools to help to document program logic (the algorithm). These are
flowcharts, structured chart, and Pseudocode
Pseudocode:- (derived from pseudo and code) is a compact and informal
high-level description of a computer algorithm that uses the structural
conventions of programming languages, but typically omits details such as
subroutines, variables declarations and system-specific syntax.
As the name suggests, pseudocode generally does not actually obey the
syntax rules of any particular language;
The purpose of using pseudocode is that it may be easier for humans to read
than conventional programming languages,
Computer Programming Basics
• When the algorithm is written out as a well-thought series of steps, it
is sometimes called PSEUDOCODE
• It is written in easy to understand language, but is written very similar to the
way that you would code it into your 3rd Generation Language
Example: HOW TO EAT A BANANA:
A DETAILED LIST OF INSTRUCTIONS
1. Using your hand, get a yellow crescent-shaped fruit called a
“banana”
2. Peel the outer skin off the banana (by breaking off the outer stem
and peeling back the yellow peel)
3. Eat the banana
1. Put a small section of banana in your mouth
2. Bite down on the banana
3. Chew the banana by opening and closing your mouth
4. Once the banana has been chewed, swallow the banana
5. Repeat until banana is finished
4. Throw out the used banana peel
Flowchart
• A flowchart (also spelled flow-chart and flow chart) is a schematic
representation of an algorithm or a process . The advantage of flowchart is
it doesn’t depend on any particular programming language, so that it can
used, to translate an algorithm to more than one programming language.
Flowchart uses different symbols (geometrical shapes) to represent
different processes.
• Writing pseudocode will save you time later during the
construction & testing phase of a program's development.
• Example:
• Write a program that obtains two integer numbers from the user. It will
print out the sum of those numbers.
• Pseudocode:
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
Example 1: - Draw flow chart of an algorithm to add two numbers
and display their result.
Algorithm description (Pseudocode)
• Read the rules of the two numbers (A and B)
• Add A and B
start
• Assign the sum of A and B to C
Read A , B
• Display the result ( c)
C=A+B

Print C

end
• 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
• 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.
• Write the algorithmic description and draw a flow chart to find the following
sum.
Sum = 1+2+3+…. + 50
Algorithmic description (pseodocode)
1. Initialize sum too and counter to 1
2. check the counter less than or equal to 50.
• Add counter to sum
• Increase counter by 1
• Repeat step 2
1.2 Else
Exit
Exercise :-
1. write a pseudo code and draw a flow chart to calculate 2 power 4
2. write a pseudo code and draw a flow chart to find and print the
largest of the three numbers.
3. write a pseudo code and draw a flow chart to calculate the sum of
numbers from 1to 10?
4. write a pseudo code and draw a flow chart to find and print an even
no in b/n 1 and 50?
Worksheet 1
Develop an algorithm for each of the following problems. Use flowchart and Pseudocode
method of developing an algorithm. An algorithm that:
1. Converts a mark for a given course to its corresponding letter-grade. (You may set
your own scale for the grading)
2. Checks if a given number is EVEN or ODD.
3. Counts and displays the number of even and odd occurrences in a given list of
integers.
4. Finds the minimum and maximum of two given numbers.
5. Finds the maximum of five given numbers.
6. Searches for the Greatest Common Divisor (GCD) of two natural numbers.
7. Searches for the Least Common Multiple (LCM) of two natural numbers.
8. Converts a decimal number to its binary equivalent.
9. That accepts two numbers and displays the product, sum, and difference of the two numbers.
10. That reads a number and print the sum of the integers up to the number, i.e.
1 + 2 + 3 + 4 + . . .+ n
11. That reads a number n and prints 2n

You might also like