0% found this document useful (0 votes)
2 views19 pages

Chapter 1

The document provides an introduction to computer programming, explaining the role of computers in data processing and the necessity of programming languages for instructing computers. It categorizes programming languages into low-level and high-level languages, detailing their characteristics and examples, as well as various programming paradigms such as procedural, structured, and object-oriented programming. Additionally, it discusses problem-solving techniques, algorithms, and the properties of effective algorithms.

Uploaded by

Gemechu Gadisa
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)
2 views19 pages

Chapter 1

The document provides an introduction to computer programming, explaining the role of computers in data processing and the necessity of programming languages for instructing computers. It categorizes programming languages into low-level and high-level languages, detailing their characteristics and examples, as well as various programming paradigms such as procedural, structured, and object-oriented programming. Additionally, it discusses problem-solving techniques, algorithms, and the properties of effective algorithms.

Uploaded by

Gemechu Gadisa
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/ 19

Chapter One

Introduction to Programming
Introduction to Computer Programming
 Computer is an Electronic data processing device which is capable of
performing Arithmetic and Logical operations.
 Computer is an Electronic Machine that Receives Data from a user through an
Input devices
 It Stores and send the processed data, to an output device
 Computers are important and widely used in our society because they are
cost-effective to solve problems in business, government, industry, education,
etc.
 In order to solve a given problem, computers must be given the correct
instruction about how they can solve it.
 Computer programs, software programs, or just programs are the
instructions that tells the computer what to do.
 Computer programming (programming or coding) is the process of
writing, testing, debugging/troubleshooting, and maintaining the source code
of computer programs.
Cont.…
• It is written by professionals known as Computer Programmers (simply
programmers).
– it 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 (Amharic, English), are
defined by syntactic and semantic rules which describe their structure and
meaning respectively.
• Many programming languages have their own written syntax and semantics
rules
• The main purpose of programming languages is to provide instructions to a
computer.
• Programming languages can be divided in to two major categories: low-level
and high-level languages.
Low-level languages
• Low-level languages are machine-dependent; they are designed to be run on a
particular computer.
• Computers only understand one language i.e. binary language(1s and 0s).
• Binary language is also known as machine language, one of low-level
languages.
• The computer easily understood these programs, but its difficult for human
beings to remember all the instructions in the form of 0s and 1s.
• Therefore, computers remained secret to a common person until other
languages such as assembly language was developed.
Assembly language is symbolic instructions and executable machine codes.
 was created to use letters 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.
 a symbolic representation of machine code
• Computers still cannot understand it. The assembly language must be
translated to machine code by a separate program called assembler.
High-level languages
• Programming in assembly language is very slow and bulky. In addition it is
hardware specific.
• The lack of portability between different computers led to the development of
high-level languages
– because they permitted a programmer to ignore many low-level details of
the computer's hardware.
• It’s easier for programmers to "think “" in the programming language.
• It also require translation to machine language before execution.
– Compilers translate the entire source code program before execution.
– Interpreters translate source code programs one line at a time.
Example FORTRAN (FORmula TRANslator), BASIC (Bingers All Purpose
Symbolic Instruction Code), PASCAL, C, C++, Java etc.
• 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.
• programming languages are characterized (categorized) is by programming
paradigm. A programming paradigm provides the programmer's view of
code execution.
Procedural 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.
• Procedures are small sections of code that perform a particular function.
• It 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.
Cont.…
Structured Programming Languages
• It is a special type of procedural programming. It provides additional tools to
manage the problems that larger programs were creating.
• Structured programming requires that programmers break program structure
into small pieces of code that are easily understood.
• The most popular structured programming languages include C, Ada, and
Pascal.
Object-Oriented Programming Languages
• it 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 performed on an object.
• A program 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.
Problem solving techniques
• Computer solves varieties of problems that can be expressed in a finite
number of steps by writing different programs.
• Problem solving is the process of transforming the
description of a problem into the solution of that problem.
– by using the knowledge of the problem domain.

– by relying on your ability to select and use appropriate


problem-solving strategies, techniques, and tools.
• In computer programming the first part focuses on defining the problem and
logical procedures to follow in solving it.
• There are system analysis and design tools (flowchart and structure chart)
to define the problem in terms of steps to its solution.
Cont….
• 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.
• The procedure, or solution is referred to as an algorithm.

• An algorithm is defined as a step-by-step sequence of instructions or


procedures that takes some value or a set of values as input and produces some
value or a set of values as output.
• There are three commonly used tools to express algorithm:-

– These are flowcharts, structured chart, and Pseudocode.

• Generally, flowcharts work well for small problems but Pseudocode is used
for larger problems.
Cont.…
1. Structured chart: is a chart representation of an algorithm or a process.
They are used in structured programming to arrange program modules into a
chart.
Example: 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  Read centigrade value Fahrenheit
 Compute Fahrenheit value
 Display Fahrenheit value
2. Flowchart: is a diagram representation of an algorithm or a process. Flowchart

uses different symbols (geometrical shapes) to represent different processes.


Cont.…
Example 1: - Write an algorithm description and Draw flow chart to add two
numbers and display their result.
Algorithm description
• Read two numbers (A and B)
• Add A and B
• Assign the sum of A and B to C
• Display the result ( C)
Cont.…
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
Cont.…
 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.
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 infinitely remain in a loop.
 Increment: - Re-initialization of the loop for the next loop.
Example 3: - Write the algorithmic description and draw a flow chart to find the
following sum. Sum = 1+2+3+…. + 50
Cont.…
Algorithmic 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
– Write sum
– Exit
Cont.…
Exercise:
1, Write the algorithmic description and draw a flow chart to Calculate grade for
ten students based on the scale:
>80-A
>60-B
>50-C
>40-D
<40-F
2. Write an algorithm description and draw a flow chart to check a number is
ODD or EVEN.
Cont.…
3. Pseudocode: (derived from pseudo and code) is an artificial and informal language
that helps programmers to develop algorithms.
Pseudocode is a "text-based" detail (algorithmic) design tool.
– It is much similar to real code.
Eg 1) : A certain company plan to give a 10% bonus to each of its employees at the end
of every year. If an employee has been working 10/more years at the company, she/he is
to get an additional birr 100. write A pseudo-code to calculate bonus for a given
employee
ACCEPT Name, Salary
Bonus=SalaryX0.1
ACCEPT Serviceyear
IF Serviceyear>10 Then
Bonus+100
ENDIF
DISPLAY Bonus
2) A pseudo-code to calculate interest rate
ACCEPT Name, Principal, Rate
Interest=Principal X Rate
DISPLAY Name, Interest
Cont.…
3) A pseudo-code that calculates grade
ACCEPT Mark, Name
IF Mark>80 Then
GradeA
ELSE IF Mark>=70 Then
GradeB
ELSE IF Mark>=60 Then
GradeC
ELSE IF Mark>=50 Then
GradeD
ELSE
GradeF
ENDIF
DISPLAY Grade, Name
Properties of an algorithm

 Finiteness: Algorithm must complete after a finite number of steps.


 Definiteness: Each step must be clearly defined, having one and only one
interpretation.
 Sequence: Each step must have a unique defined preceding and succeeding
step. The first step (start step) and last step (halt step) must be clearly noted.
 Correctness: It must compute correct answer for all possible legal inputs
 Language Independence: It must not depend on any programming language.
 Completeness: It must solve the problem completely.
 Effectiveness: It must be possible to perform each step exactly and in a finite
amount of time.
 Efficiency: It must solve with the least amount of computational resources
such as time and space.
 Generality: Algorithm should be valid on all possible inputs.
 Input/Output: There must be a specified number of input values, and one or
more result values.

You might also like