SlideShare a Scribd company logo
Chapter One
Introduction to programming
Department of Computer Science
Computer programming
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 produces meaningful information in a
form that is useful to the user.
โ€ข They have been deployed to solve different real life problems, from
the simplest game playing up to the complex nuclear energy
production.
โ€ข Computers are important and widely used in our society because
they are cost-effective aids to problem solving in business,
government, industry, education, etc.
Cont.โ€ฆ
โ€ข In order to solve a given problem, computers must be given the
correct instruction about how they can solve it.
โ€ข The terms computer programs, software programs, or just programs
are the instructions that tells the computer what to do.
โ€ข Computer requires programs to function, and a 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.
โ€ข Each instruction is relatively simple, yet because of the computer's
speed, it is able to run millions of instructions in a second.
โ€ข A computer program usually consists of two elements:
โ€ข Data โ€“ characteristics
โ€ข Code โ€“ action
โ€ข Computer programs (also know as source code) is often written by
professionals known as Computer Programmers (simply programmers).
Cont.โ€ฆ
โ€ข 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 (such as Amharic), 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 semantic
Cont.โ€ฆ
โ€ข Programming languages allow humans to communicate instructions
to machines.
โ€ข A main purpose of programming languages is to provide instructions
to a computer.
โ€ข Programming languages differ from most other forms of human
expression in that they require a greater degree of precision and
completeness.
โ€ข When using a natural language to communicate with other people,
human authors and speakers can be ambiguous and make small
errors, and still expect their intent to be understood.
Cont.โ€ฆ
โ€ข Computers do exactly what they are told to do, and cannot
understand the code the programmer "intended" to write.
โ€ข So computers need to be instructed to perform all the tasks.
โ€ข The combination of the language definition, the program, and the
program's inputs must fully specify the external behavior that occurs
when the program is executed.
โ€ข 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.
Cont.โ€ฆ
โ€ข Available programming languages come in a variety of forms and
types.
โ€ข Thousands of different programming languages have been developed,
used, and discarded.
โ€ข Programming languages can be divided in to two major categories:
๏ƒ˜low-level and
๏ƒ˜ high-level languages.
Cont.โ€ฆ
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.
โ€ข In the initial years of computer programming, all the instructions were given
in binary form.
โ€ข Although the computer easily understood these programs, it proved too
difficult for a normal human being to remember all the instructions in the
form of 0s and 1s.
โ€ข Therefore, computers remained mystery to a common person until other
languages such as assembly language was developed, which were easier to
learn and understand.
โ€ข 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
โ€ข Assembly language is nothing more than a symbolic representation of
machine code, which allows symbolic designation of memory
locations.
โ€ข However, no matter how close assembly language is to machine code,
computers still cannot understand it.
Cont.โ€ฆ
โ€ข 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).
โ€ข Assemblers are written for each unique machine language.
โ€ข Although programming in assembly language is not as difficult and error
prone as stringing together ones and zeros, it is slow and cumbersome.
โ€ข In addition it is hardware specific.
Cont.โ€ฆ
High-level languages
โ€ข The lack of portability between different computers led to the
development of high-level languagesโ€”so called because they
permitted a programmer to ignore many low-level details of the
computer's hardware.
โ€ข Further, it was recognized that the closer the syntax, rules, and
mnemonics of the programming language could be to "natural
language" the less likely it became that the programmer would
inadvertently introduce errors (called "bugs") into the program.
โ€ข High-level languages are more English-like and, therefore, make it
easier for programmers to "think" in the programming language.
โ€ข High-level languages also require translation to machine language
before execution.
โ€ข This translation is accomplished by either a compiler or an
interpreter.
โ€ข 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.
โ€ข FORTRAN (FORmula TRANslator), BASIC (Bingers All Purpose Symbolic
Instruction Code), PASCAL, C, C++, Java are some examples of high-
level languages.
Cont.โ€ฆ
โ€ข The question of which language is best is one that consumes a lot of
time and energy among computer professionals.
โ€ข 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
Cont.โ€ฆ
โ€ข As might be expected in a dynamic and evolving field, there is no
single standard for classifying programming languages.
โ€ข Another most fundamental ways programming languages are
characterized (categorized) is by programming paradigm.
โ€ข A programming paradigm provides the programmer's view of code
execution.
Cont.โ€ฆ
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.
โ€ข 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.
Cont.โ€ฆ
Structured Programming Languages
โ€ข Structured programming 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.
โ€ข It also frowns upon the use of global variables and instead uses
variables local to each subroutine.
โ€ข One of the well-known features of structural programming is that it
does not allow the use of the GOTO statement.
โ€ข It is often associated with a "top-down" approach to design.
โ€ข The top-down approach begins with an initial overview of the system
that contains minimal details about the different parts.
โ€ข Subsequent design iterations then add increasing detail to the
components until the design is complete.
โ€ข The most popular structured programming languages include C, Ada,
and Pascal.
Cont.โ€ฆ
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.
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.
โ€ข 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.
Cont.โ€ฆ
โ€ข 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.
โ€ข 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 Pseudo code.
โ€ข Generally, flowcharts work well for small problems but Pseudo code
is used for larger problems.
Cont.โ€ฆ
Pseudo code
โ€ข 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
detailes such as subroutines, variables declarations and system-
specific syntax.
โ€ข The programming language is augmented with natural language
descriptions of the details, where convenient, or with compact
mathematical notation.
โ€ข The purpose of using pseudocode is that it may be easier for humans
to read than conventional programming languages, and that it may be
a compact and environment-independent generic description of the
key principles of an algorithm.
โ€ข No standard for pseudocode syntax exists, as a program in
pseudocode is not an executable program.
โ€ข As the name suggests, pseudocode generally does not actually obey
the synatx rules of any particular language;
โ€ข there is no systematic standard form, although any particular writer
will generally borrow the appearance of a particular language.
Cont.โ€ฆ
โ€ข The programming process is a complicated one.
โ€ข You must first understand the program specifications, of course, Then
you need to organize your 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 pseudo code will save you time later during the construction
& testing phase of a program's development.
Cont.โ€ฆ
Example:
โ€ข Original Program Specification:
๏ƒ˜Write a program that obtains two integer numbers from the user. It
will print out the sum of those numbers.
โ€ข Pseudocode:
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
Cont.โ€ฆ
โ€ข Example: pseudo code for a program that calculates the area of a
square:
๏ƒ˜Get the length of one side
๏ƒ˜Multiply the length by itself
๏ƒ˜Store the result in a variable called area
๏ƒ˜Display the area
Cont.โ€ฆ
Structured Charts
โ€ข Structured 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.
โ€ข 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 ๏‚ท Prompt for centigrade value
๏‚ท Read centigrade value
๏‚ท Compute Fahrenheit value
๏‚ท Display Fahrenheit value
Fahrenheit
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.
The following table shows some of the common
symbols.
โ€ข 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)
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.
โ€ข Loop is a sequence of instructions, which is repeated until some specific
condition occurs.
โ€ข 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.
Cont.โ€ฆ
โ€ข Example 3: - Write the algorithmic description and draw a flow chart to find the
following sum.
โ€ข Sum = 1+2+3+โ€ฆ. + 50
โ€ข Algorithmic description
1. Initialize sum too and counter to 1
โ€ข If the counter is less than or equal to 50
โ€ข Add counter to sum
โ€ข Increase counter by 1
โ€ข Repeat step 1.1
Else
โ€ข Exit
2. Write sum
Cont.โ€ฆ
System Development Life Cycle (SDLC)
โ€ข The Systems 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.
โ€ข Feasibility study
๏ƒ˜The first step is to identify a need for the new system.
๏ƒ˜This will include determining whether a business problem or
opportunity exists, conducting a feasibility study to determine if the
proposed solution is cost effective, and developing a project plan.
๏ƒ˜This process may involve end users who come up with an idea for
improving their work or may only involve IS people.
โ€ข Ideally, the process occurs in tandem with a review of the
organization's strategic plan to ensure that IT is being used to help
the organization achieve its strategic objectives.
โ€ข Management may need to approve concept ideas before any money
is budgeted for its development.
โ€ข A preliminary analysis, determining the nature and scope of the
problems to be solved is carried out.
โ€ข Possible solutions are proposed, describing the cost and benefits.
โ€ข Finally, a preliminary plan for decision making is produced.
Cont.โ€ฆ
โ€ข The process of developing a large information system can be very
costly, and the investigation stage may require a preliminary study
called a feasibility study, which includes e.g. the following
components:
๏ƒ˜Organizational Feasibility
๏ƒ˜Economic Feasibility
๏ƒ˜Technical Feasibility
๏ƒ˜Operational Feasibility
Cont.โ€ฆ
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
c. Technical Feasibility
๏ƒ˜Hardware, software, and network capability, reliability, and availability
d. Operational Feasibility
๏ƒ˜ End user acceptance
๏ƒ˜ Management support
๏ƒ˜ Customer, supplier, and government requirements
Cont.โ€ฆ
Requirements analysis
โ€ข 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.
โ€ข Also, the requirements should be recorded in a document, email, user
interface storyboard, executable prototype, or some other form.
โ€ข The requirements documentation should be referred to throughout the
rest of the system development process to ensure the developing project
aligns with user needs and requirements.
โ€ข End users must be involved in this process to ensure that the new system
will function adequately and meets their needs and expectations.
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.
โ€ข The created system design, but must reviewed by users to ensure the
design meets users' needs.
Testing designed solution
โ€ข A smaller test system is sometimes a good idea in order to get a โ€œproof-
of-conceptโ€ validation prior to committing funds for large scale fielding
of a system without knowing if it really works as intended by the user.
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.
โ€ข The key to understanding the implementation phase is to realize that
there is a lot more to be done than programming.
โ€ข Implementation requires programming, but it also requires database
creation and population, and network installation and testing.
โ€ข You also need to make sure the people are taken care of with effective
training and documentation.
โ€ข Finally, if you expect your development skills to improve over time,
you need to conduct a review of the lessons learned.
Unit testing
โ€ข Normally programs are written as a series of individual modules,
these subject to separate and detailed test.
Integration and System testing
โ€ข Brings all the pieces together into a special testing environment, then
checks for errors, bugs and interoperability.
โ€ข The system is tested to ensure that interfaces between modules work
(integration testing), the system works on the intended platform and
with the expected volume of data (volume testing) and that the
system does what the user requires (acceptance/beta testing).
Maintenance
โ€ข What happens during the rest of the software's life: changes,
correction, additions, moves to a different computing platform and
more.
โ€ข This, the least glamorous and perhaps most important step of all,
goes on seemingly forever.
Thank you !!

More Related Content

Similar to computer programming computer programmin (20)

PPT
Chapter 1- C++ programming languages +.ppt
anawaarabdujabbaar
ย 
PDF
Introduction to computer programming language
hidrahrama
ย 
PPTX
Programming Paradigm & Languages
Gaditek
ย 
PPTX
Programming Paradigm & Languages
Gaditek
ย 
PPTX
Python Programming-Skill Course - unit-i.pptx
KavithaDonepudi
ย 
PPTX
Python-unit -I.pptx
crAmth
ย 
PPTX
Program Logic and Design
Froilan Cantillo
ย 
PPTX
Chapter 2.pptx
TamiratDejene1
ย 
PPTX
01-PROGRAMMING introA of the class name. Pptx
simukondasankananji8
ย 
PPT
Introduction Programming Languages
Manish Kharotia
ย 
PDF
A Short Communication On Computer Programming Languages In Modern Era
Katie Naple
ย 
PDF
La5 ict-topic-5-programming
Kak Yong
ย 
PPTX
Plc part 1
Taymoor Nazmy
ย 
PPTX
Presentation-1.pptx
animewatcher7
ย 
PPTX
Introduction to programming languages
samina khan
ย 
PPT
English de lenguaje de programacion
Villalba Griselda
ย 
PPTX
Software programming and development
Ali Raza
ย 
PDF
Introduction To Programming In C Language C Programming Best C Programming La...
simanuaderli
ย 
PPTX
Programming Fundamentals and Programming Languages Concepts
imtiazalijoono
ย 
Chapter 1- C++ programming languages +.ppt
anawaarabdujabbaar
ย 
Introduction to computer programming language
hidrahrama
ย 
Programming Paradigm & Languages
Gaditek
ย 
Programming Paradigm & Languages
Gaditek
ย 
Python Programming-Skill Course - unit-i.pptx
KavithaDonepudi
ย 
Python-unit -I.pptx
crAmth
ย 
Program Logic and Design
Froilan Cantillo
ย 
Chapter 2.pptx
TamiratDejene1
ย 
01-PROGRAMMING introA of the class name. Pptx
simukondasankananji8
ย 
Introduction Programming Languages
Manish Kharotia
ย 
A Short Communication On Computer Programming Languages In Modern Era
Katie Naple
ย 
La5 ict-topic-5-programming
Kak Yong
ย 
Plc part 1
Taymoor Nazmy
ย 
Presentation-1.pptx
animewatcher7
ย 
Introduction to programming languages
samina khan
ย 
English de lenguaje de programacion
Villalba Griselda
ย 
Software programming and development
Ali Raza
ย 
Introduction To Programming In C Language C Programming Best C Programming La...
simanuaderli
ย 
Programming Fundamentals and Programming Languages Concepts
imtiazalijoono
ย 

Recently uploaded (20)

PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
PDF
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
PDF
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
ย 
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
ย 
PPTX
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
ย 
PDF
Which Hiring Management Tools Offer the Best ROI?
HireME
ย 
PPTX
Agentforce โ€“ TDX 2025 Hackathon Achievement
GetOnCRM Solutions
ย 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
PDF
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
ย 
PPTX
For my supp to finally picking supp that work
necas19388
ย 
PDF
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
ย 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
PPTX
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
PDF
Mastering VPC Architecture Build for Scale from Day 1.pdf
Devseccops.ai
ย 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
PDF
Rewards and Recognition (2).pdf
ethan Talor
ย 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
ย 
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
ย 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
ย 
Which Hiring Management Tools Offer the Best ROI?
HireME
ย 
Agentforce โ€“ TDX 2025 Hackathon Achievement
GetOnCRM Solutions
ย 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
ย 
For my supp to finally picking supp that work
necas19388
ย 
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
ย 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
Mastering VPC Architecture Build for Scale from Day 1.pdf
Devseccops.ai
ย 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
Rewards and Recognition (2).pdf
ethan Talor
ย 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
Ad

computer programming computer programmin

  • 1. Chapter One Introduction to programming Department of Computer Science Computer programming
  • 2. 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 produces meaningful information in a form that is useful to the user. โ€ข They have been deployed to solve different real life problems, from the simplest game playing up to the complex nuclear energy production. โ€ข Computers are important and widely used in our society because they are cost-effective aids to problem solving in business, government, industry, education, etc.
  • 3. Cont.โ€ฆ โ€ข In order to solve a given problem, computers must be given the correct instruction about how they can solve it. โ€ข The terms computer programs, software programs, or just programs are the instructions that tells the computer what to do. โ€ข Computer requires programs to function, and a 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.
  • 4. โ€ข Writing computer programs means writing instructions, that will make the computer follow and run a program based on those instructions. โ€ข Each instruction is relatively simple, yet because of the computer's speed, it is able to run millions of instructions in a second. โ€ข A computer program usually consists of two elements: โ€ข Data โ€“ characteristics โ€ข Code โ€“ action โ€ข Computer programs (also know as source code) is often written by professionals known as Computer Programmers (simply programmers). Cont.โ€ฆ
  • 5. โ€ข 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 (such as Amharic), 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 semantic Cont.โ€ฆ
  • 6. โ€ข Programming languages allow humans to communicate instructions to machines. โ€ข A main purpose of programming languages is to provide instructions to a computer. โ€ข Programming languages differ from most other forms of human expression in that they require a greater degree of precision and completeness. โ€ข When using a natural language to communicate with other people, human authors and speakers can be ambiguous and make small errors, and still expect their intent to be understood. Cont.โ€ฆ
  • 7. โ€ข Computers do exactly what they are told to do, and cannot understand the code the programmer "intended" to write. โ€ข So computers need to be instructed to perform all the tasks. โ€ข The combination of the language definition, the program, and the program's inputs must fully specify the external behavior that occurs when the program is executed. โ€ข 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. Cont.โ€ฆ
  • 8. โ€ข Available programming languages come in a variety of forms and types. โ€ข Thousands of different programming languages have been developed, used, and discarded. โ€ข Programming languages can be divided in to two major categories: ๏ƒ˜low-level and ๏ƒ˜ high-level languages. Cont.โ€ฆ
  • 9. 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. โ€ข In the initial years of computer programming, all the instructions were given in binary form. โ€ข Although the computer easily understood these programs, it proved too difficult for a normal human being to remember all the instructions in the form of 0s and 1s. โ€ข Therefore, computers remained mystery to a common person until other languages such as assembly language was developed, which were easier to learn and understand.
  • 10. โ€ข 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 โ€ข Assembly language is nothing more than a symbolic representation of machine code, which allows symbolic designation of memory locations. โ€ข However, no matter how close assembly language is to machine code, computers still cannot understand it. Cont.โ€ฆ
  • 11. โ€ข 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). โ€ข Assemblers are written for each unique machine language. โ€ข Although programming in assembly language is not as difficult and error prone as stringing together ones and zeros, it is slow and cumbersome. โ€ข In addition it is hardware specific. Cont.โ€ฆ
  • 12. High-level languages โ€ข The lack of portability between different computers led to the development of high-level languagesโ€”so called because they permitted a programmer to ignore many low-level details of the computer's hardware. โ€ข Further, it was recognized that the closer the syntax, rules, and mnemonics of the programming language could be to "natural language" the less likely it became that the programmer would inadvertently introduce errors (called "bugs") into the program. โ€ข High-level languages are more English-like and, therefore, make it easier for programmers to "think" in the programming language.
  • 13. โ€ข High-level languages also require translation to machine language before execution. โ€ข This translation is accomplished by either a compiler or an interpreter. โ€ข 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. โ€ข FORTRAN (FORmula TRANslator), BASIC (Bingers All Purpose Symbolic Instruction Code), PASCAL, C, C++, Java are some examples of high- level languages. Cont.โ€ฆ
  • 14. โ€ข The question of which language is best is one that consumes a lot of time and energy among computer professionals. โ€ข 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 Cont.โ€ฆ
  • 15. โ€ข As might be expected in a dynamic and evolving field, there is no single standard for classifying programming languages. โ€ข Another most fundamental ways programming languages are characterized (categorized) is by programming paradigm. โ€ข A programming paradigm provides the programmer's view of code execution. Cont.โ€ฆ
  • 16. 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. โ€ข 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.
  • 17. โ€ข 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. Cont.โ€ฆ
  • 18. Structured Programming Languages โ€ข Structured programming 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. โ€ข It also frowns upon the use of global variables and instead uses variables local to each subroutine.
  • 19. โ€ข One of the well-known features of structural programming is that it does not allow the use of the GOTO statement. โ€ข It is often associated with a "top-down" approach to design. โ€ข The top-down approach begins with an initial overview of the system that contains minimal details about the different parts. โ€ข Subsequent design iterations then add increasing detail to the components until the design is complete. โ€ข The most popular structured programming languages include C, Ada, and Pascal. Cont.โ€ฆ
  • 20. 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.
  • 21. 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.
  • 22. โ€ข 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. Cont.โ€ฆ
  • 23. โ€ข 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. โ€ข 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 Pseudo code. โ€ข Generally, flowcharts work well for small problems but Pseudo code is used for larger problems. Cont.โ€ฆ
  • 24. Pseudo code โ€ข 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 detailes such as subroutines, variables declarations and system- specific syntax. โ€ข The programming language is augmented with natural language descriptions of the details, where convenient, or with compact mathematical notation.
  • 25. โ€ข The purpose of using pseudocode is that it may be easier for humans to read than conventional programming languages, and that it may be a compact and environment-independent generic description of the key principles of an algorithm. โ€ข No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program. โ€ข As the name suggests, pseudocode generally does not actually obey the synatx rules of any particular language; โ€ข there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language. Cont.โ€ฆ
  • 26. โ€ข The programming process is a complicated one. โ€ข You must first understand the program specifications, of course, Then you need to organize your 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 pseudo code will save you time later during the construction & testing phase of a program's development. Cont.โ€ฆ
  • 27. Example: โ€ข Original Program Specification: ๏ƒ˜Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. โ€ข Pseudocode: 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 Cont.โ€ฆ
  • 28. โ€ข Example: pseudo code for a program that calculates the area of a square: ๏ƒ˜Get the length of one side ๏ƒ˜Multiply the length by itself ๏ƒ˜Store the result in a variable called area ๏ƒ˜Display the area Cont.โ€ฆ
  • 29. Structured Charts โ€ข Structured 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. โ€ข 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 ๏‚ท Prompt for centigrade value ๏‚ท Read centigrade value ๏‚ท Compute Fahrenheit value ๏‚ท Display Fahrenheit value Fahrenheit
  • 30. 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.
  • 31. The following table shows some of the common symbols.
  • 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) Cont.โ€ฆ
  • 33. โ€ข 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.โ€ฆ
  • 34. โ€ข 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. โ€ข 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. Cont.โ€ฆ
  • 35. โ€ข Example 3: - Write the algorithmic description and draw a flow chart to find the following sum. โ€ข Sum = 1+2+3+โ€ฆ. + 50 โ€ข Algorithmic description 1. Initialize sum too and counter to 1 โ€ข If the counter is less than or equal to 50 โ€ข Add counter to sum โ€ข Increase counter by 1 โ€ข Repeat step 1.1 Else โ€ข Exit 2. Write sum Cont.โ€ฆ
  • 36. System Development Life Cycle (SDLC) โ€ข The Systems 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. โ€ข Feasibility study ๏ƒ˜The first step is to identify a need for the new system. ๏ƒ˜This will include determining whether a business problem or opportunity exists, conducting a feasibility study to determine if the proposed solution is cost effective, and developing a project plan. ๏ƒ˜This process may involve end users who come up with an idea for improving their work or may only involve IS people.
  • 37. โ€ข Ideally, the process occurs in tandem with a review of the organization's strategic plan to ensure that IT is being used to help the organization achieve its strategic objectives. โ€ข Management may need to approve concept ideas before any money is budgeted for its development. โ€ข A preliminary analysis, determining the nature and scope of the problems to be solved is carried out. โ€ข Possible solutions are proposed, describing the cost and benefits. โ€ข Finally, a preliminary plan for decision making is produced. Cont.โ€ฆ
  • 38. โ€ข The process of developing a large information system can be very costly, and the investigation stage may require a preliminary study called a feasibility study, which includes e.g. the following components: ๏ƒ˜Organizational Feasibility ๏ƒ˜Economic Feasibility ๏ƒ˜Technical Feasibility ๏ƒ˜Operational Feasibility Cont.โ€ฆ
  • 39. 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 c. Technical Feasibility ๏ƒ˜Hardware, software, and network capability, reliability, and availability d. Operational Feasibility ๏ƒ˜ End user acceptance ๏ƒ˜ Management support ๏ƒ˜ Customer, supplier, and government requirements Cont.โ€ฆ
  • 40. Requirements analysis โ€ข 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. โ€ข Also, the requirements should be recorded in a document, email, user interface storyboard, executable prototype, or some other form. โ€ข The requirements documentation should be referred to throughout the rest of the system development process to ensure the developing project aligns with user needs and requirements. โ€ข End users must be involved in this process to ensure that the new system will function adequately and meets their needs and expectations.
  • 41. 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. โ€ข The created system design, but must reviewed by users to ensure the design meets users' needs. Testing designed solution โ€ข A smaller test system is sometimes a good idea in order to get a โ€œproof- of-conceptโ€ validation prior to committing funds for large scale fielding of a system without knowing if it really works as intended by the user.
  • 42. 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. โ€ข The key to understanding the implementation phase is to realize that there is a lot more to be done than programming. โ€ข Implementation requires programming, but it also requires database creation and population, and network installation and testing. โ€ข You also need to make sure the people are taken care of with effective training and documentation. โ€ข Finally, if you expect your development skills to improve over time, you need to conduct a review of the lessons learned.
  • 43. Unit testing โ€ข Normally programs are written as a series of individual modules, these subject to separate and detailed test. Integration and System testing โ€ข Brings all the pieces together into a special testing environment, then checks for errors, bugs and interoperability. โ€ข The system is tested to ensure that interfaces between modules work (integration testing), the system works on the intended platform and with the expected volume of data (volume testing) and that the system does what the user requires (acceptance/beta testing).
  • 44. Maintenance โ€ข What happens during the rest of the software's life: changes, correction, additions, moves to a different computing platform and more. โ€ข This, the least glamorous and perhaps most important step of all, goes on seemingly forever.