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

Programming Lecture 1

Uploaded by

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

Programming Lecture 1

Uploaded by

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

Lecture One

Computer Programming
IT

BY Basha K | Faculty of Computing and Software Engineering |


AMIT
Programming I BY Basha K, 2022 Programming Lecture 1 2

Topics Covered

• Introduction to programming

• Problem solving techniques

• Flowchart

• Pseudo code

• Algorithms
Programming I BY Basha K, 2022 Programming Lecture 1 3

Introduction
• What is a computer?

• 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 produces meaningful information in a form that is
useful to the user.
Inputs Process Outputs
Programming I BY Basha K, 2022 Programming Lecture 1 4

What is a program?
• 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
Programming I BY Basha K, 2022 Programming Lecture 1 5

Conti…
• A computer program consists of two elements:
• Code – action

• Data – characteristics

• Computer programs (also know as source code) is often

written by professionals known as Computer Programmers.

• Source code is written in one of programming languages.


Programming I BY Basha K, 2022 Programming Lecture 1 6

Programming language
• 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.


Programming I BY Basha K, 2022 Programming Lecture 1 7

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

Levels of Programming Languages

• Programs and programming languages have been in existence since the

invention of computers.
• There are three levels of programming languages. These are:

1) Machine Language: Machine language is a set binary coded instruction,

which consists of zeros (0) and ones (1).

• Machine language is peculiar to each type of computer.

• The first generation of computers was coded in machine

language that was specific to each model of computer.


Programming I BY Basha K, 2022 Programming Lecture 1

Some of the shortcomings of the machine language were:

1. Coding in machine language was a very tedious and boring job


2. Machine language was not user-friendly.
• That is the user had to remember a long list of codes, numbers or operation codes

and know where instructions were stored in computer memory.

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.

• The major advantage of machine language is that it requires no translation

since it is already in machine language and is therefore faster to execute.


Programming I BY Basha K, 2022 Programming Lecture 1

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

addresses in machine language.


• Assembly language is also called Symbolic language, because it makes use of an

assembler to translate codes into machine language.


Programming I BY Basha K, 2022 Programming Lecture 1 11

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

However, no matter how close assembly language is to machine


code, computers still cannot understand it.
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. Thus assembly
languages are unique to a specific computer (machine).
Programming I BY Basha K, 2022 Programming Lecture 1

Conti…
• The disadvantages of assembly language are that:

• It is specific to particular machines

• It requires a translator called an assembler.

• The major advantage of the assembly language is that programs

written in it are:-
 Easier to read and more user friendly than those written in machine

language, especially when comments are inserted in the codes


Programming I BY Basha K, 2022 Programming Lecture 1

3. High Level Language:

• This programming language consists of English-like codes.

• It is machine independent language

• It is independent of the computer because the programmer only needs to pay

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…

Some advantages of high-level language:

• It is more user friendly, that is, easy to learn and write

• It is very portable, that is, it can be used on almost any computer

• It saves much time and effort when used compared to any other

programming level language.


• Codes written in this language can easily be debugged.

• But it requires translator program called compiler or interpreter i.e.;

translates programs written in high level language to machine code.


Programming I BY Basha K, 2022 Programming Lecture 1

Features of Programming Languages


 There are some conventional features which a programming language must

possess, these features are:


• It must have syntactic rules for forming statements.

• It must have a vocabulary that consists of letters of the alphabet.

• It must have a language structure, which consists of keywords, expressions and

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

programming language other than the machine language to an understandable set


of codes for the computer and in so doing produces a program that may be
executed on the computer.
• The need for a translator arises because only a program that is directly executable

on a computer is the machine language.


• Examples of a translator are:-

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

• They exist to make programs understandable by the computer

• There exist different translators for different levels and types of

programming languages
• Without them, the programs cannot be executed.
Programming I BY Basha K, 2022 Programming Lecture 1

2. Interpreters and Compilers:

• These consist of programs that convert programs in high level

programming language into machine language.


• The major difference between interpreters and compilers is

that a:-
 A compiler converts the entire source program into object code before

the entire program is executed


 Interpreter translates the source instructions line by line.

• In the former, the computer immediately executes one instruction

before translating the next instruction


Programming I BY Basha K, 2022 Programming Lecture 1 19

Programming paradigms

1. Procedural Programming Languages


2. Object-Oriented Programming Languages
Programming I BY Basha K, 2022 Programming Lecture 1 20

1. Procedural Programming Languages


 is a list of instructions telling a computer, step-by-step, what to do, usually having a linear

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

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.


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

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


 E.g. FORTRAN and BASIC.
Programming I BY Basha K, 2022 Programming Lecture 1 21

2. Object-Oriented Programming Languages


Object-oriented programming is one the newest and most powerful paradigms.

Object-oriented programming is a programming paradigms based on the concept

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

each object has a distinct, limited role.


Programming I BY Basha K, 2022 Programming Lecture 1 22

Problem Solving Techniques


• Computer solves varieties of problems that can be expressed in a finite

number of steps leading to a precisely defined goal by writing different


programs.
• A program is not needed only to solve a problem but also it should be

reliable, (maintainable) portable and efficient.


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

• The second introduces the means by which programmers communicate those procedures to the

computer system so that it can be executed.


Programming I BY Basha K, 2022 Programming Lecture 1 23

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

solution to the computer.


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, selected is referred to as an algorithm.

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.
Programming I BY Basha K, 2022 Programming Lecture 1

Conti…

Figure.1: The position of algorithms in problem solving


Programming I BY Basha K, 2022 Programming Lecture 1 25

Algorithms

• Simply, algorithm is a sequence of instructions.

• Algorithms are a fundamental part of computing.

• 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, not to be specific.

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

• Pseudo code is independent of any programming language. Pseudo code (or a

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

algorithm that uses the structural conventions of programming languages, but


typically omits details such as subroutines, variables declarations and system-
specific syntax.
• No standard for pseudocode syntax exists, as a program in pseudocode is not an

executable program.
• The purpose of using pseudocode is that it may be easier for humans to read

than conventional programming languages


Programming I BY Basha K, 2022 Programming Lecture 1 27

Pseudocode
• As the name suggests, pseudocode generally does not actually obey the syntax rules

of any particular language; there is no systematic standard form, although any


particular writer will generally borrow the appearance of a particular language.
• The programming process is a complicated one.

• You must first understand the program specifications, of course, Then you need to

organize thoughts and create the program.


• This is a difficult task when the program is not trivial (i.e. easy).

• You must break the main tasks that must be accomplished into smaller ones in order

to be able to eventually write fully developed code.


• Writing pseudocode will save time later during the construction & testing phase of

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

• 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.
Programming I BY Basha K, 2022 Programming Lecture 1 30

Flowcharts Symbol and Meanings


Programming I BY Basha K, 2022 Programming Lecture 1 31

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:

• Draw flow chart of an algorithm to add two numbers and

display their result.


• Algorithm description
• Read the rules of the two numbers (A and B)

• Add A and B

• Assign the sum of A and B to C

• Display the result ( c)


Programming I BY Basha K, 2022 Programming Lecture 1 33
Programming I BY Basha K, 2022 Programming Lecture 1 34

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

• Write the algorithm description (Pseudo code) and Draw flow


chart of an algorithm to find the following sum.
Sum = 1+2+3+…. + 50
• Algorithm description (Pseudo code)

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

You might also like