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

Chapter 1

This document provides an introduction to programming concepts including: - Computers accept data, perform computations according to instructions, and produce useful information for users. Computer programs contain instructions that control this processing. - Programming involves writing, testing, debugging, and maintaining source code. Programs are written by programmers in programming languages and consist of data and code. - Programming languages have syntactic and semantic rules and can be high-level or low-level. High-level languages are easier for humans but must be compiled into machine-level code. Interpreters translate each line immediately rather than compiling the entire program. - Structured programming divides programs into modules. Object-oriented programming groups data and operations into objects that

Uploaded by

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

Chapter 1

This document provides an introduction to programming concepts including: - Computers accept data, perform computations according to instructions, and produce useful information for users. Computer programs contain instructions that control this processing. - Programming involves writing, testing, debugging, and maintaining source code. Programs are written by programmers in programming languages and consist of data and code. - Programming languages have syntactic and semantic rules and can be high-level or low-level. High-level languages are easier for humans but must be compiled into machine-level code. Interpreters translate each line immediately rather than compiling the entire program. - Structured programming divides programs into modules. Object-oriented programming groups data and operations into objects that

Uploaded by

eshetu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Chapter: One

Introduction to programming
 Computer ?
 an electronic device that accepts data, performs computations,
and makes logical decisions according to instructions that have
been given to it.
 then produces meaningful information in a form that is useful
to the user
 Computer programs ?
 Sets of instructions that control a computer’s processing of data
 the instructions that tells the computer what to do
 Computer programming ?
 is the process of writing, testing, debugging / troubleshooting,
and maintaining the source code of computer programs
Introduction to programming
 Computer programs (also known as source code) is often
written by professionals known as Computer Programmers
 A computer program usually consists of two elements:
 Data – characteristics
 Code – action
 Source code is written in one of programming languages
Introduction to programming
What is Programming Language?
 Is an artificial language that can be used to control the behavior
of a computer
 defined by
 Syntactic - describes the possible combinations of symbols
that form a syntactically correct program
 Semantic - The meaning given to a combination of symbols
 computers do exactly what they are told to do
 Programming languages can be divided in to two major categories:
low-level
high-level languages
Introduction to programming
 Machine language
 machine is short for computing machine (i.e., computer)
 computer’s native language, sequence of zeroes and ones (binary)
 different computers understand different sequences
 hard for humans to understand: 01010001…
 Assembly language
 mnemonics for machine language
 low level: each instruction is minimal
 still hard for humans to understand: ADD d0,d2
 High-level languages
 FORTRAN, Pascal, BASIC, C, C++, Java, COBOL, etc.
 high level: each instruction composed of many low-level
instructions
 closer to English easier to read and understand:
hypotenuse = Math.sqrt(opposite *opposite + adjacent * adjacent);
Interpreting Vs Compiling Program
 Each type of computer only “understands” its own machine
language (zeroes and ones)
 Thus we must translate from High-level language to machine
language
◦ a team of experts programs a translator, called a “compiler” which
translates entirety of a High-level language program to an
executable file in computer’s native machine language.
 Running :
◦ compilation: Your program  executable
◦ execution: run executable
 machine executes your program by “running” each machine
language instruction in the executable file
Interpreting Vs Compiling Program
 An alternative to compiling your program is to interpret your
program
◦ each line of your program is translated into machine language
and immediately executed

 Like translating between natural languages


◦ Compiler: human translator translates book in its entirety and
then translated book is printed and read
◦ Interpreter: human interpreter translates each spoken statement
in sequence as speaker is speaking
Programming paradigm
 A programming paradigm is a fundamental style of
programming
 Unstructured Programming
 Procedural programming .
 Structured Programming
 Object Oriented Programming
Unstructured Programming
 consisting only of one large (usually main) program
 “main program”' stands for a sequence of commands or
statements
◦ data is global throughout the whole program

 disadvantages
◦ Complex
◦ if the same statement sequence is needed at different
locations within the program, the sequence must be copied
Procedural programming
 based upon the concept of procedure call
 A procedure call is used to invoke the procedure
 Procedures (routines, subroutines, methods, functions) simply
contain a series of computational steps to be carried out to solve a
problem
Procedural programming
• We have a single program, which is divided into small pieces
called procedures

•Advantage
•to re-use the same code at different places in the program
without copying it
•easier way to keep track of program flow
•Example
•FORTRAN, ADA
Structured Programming
 is a subset of procedural programming (also known as modular
programming)
 procedures of a common functionality are grouped together into
separate modules
 Each module can have its own data
◦ allows each module to manage an internal state which is
modified by calls to procedures of this module
 top-down design model
◦ map out the overall program structure into separate subsections
 Example
◦ PASCAL, C
Structured Programming
 Advantage
◦ Reuse
◦ Easier to understand and modify
Object Oriented Programming
 Is a method of implementation in which programs are organized
as cooperative collections of objects
 Data and operations are grouped together
 Each object is capable of receiving messages, processing data,
and sending messages to other objects
 Modeling of the domain as objects so that the implementation
naturally reflects the problem at hand.
Problem solving Techniques
 Computer solves varieties of problems that can be expressed in
a finite number of steps
 In computer programming two facts :
 Defining the problem and logical procedures to follow in
solving it.
Introducing the means by which programmers
communicate those procedures to the computer system so
that it can be executed.
Problem solving Techniques
 There are system analysis and design tools, particularly
flowchart and structure chart, that can be used to define the
problem in terms of the steps to its solution.
 The programmer uses programming language to
communicate the logic of the solution to the computer.
 An algorithm is defined as a step-by-step sequence of
instructions that must terminate and describe how the data is
to be processed to produce the desired outputs.
 Simply, algorithm is a sequence of instructions
Problem solving Techniques
 programs could be written in terms of 3 structures:
◦ Sequence – which instruction should be done next?
◦ Selection – select between options
◦ Repetition – repeat an action while a given condition stays
true
 An algorithm can be represented as
◦ Flowchart
◦ Pseudo code
◦ Structured chart
Pseudo code
 is an artificial and informal language that helps programmers
develop algorithms
 a shorthand notation for programming which uses a combination
of informal programming structures and verbal descriptions of
code.
 In general, pseudocode is used to outline a program before
translating it into proper syntax.
Pseudo code
Example-1:
◦ Write a program that prints “passed” when the student
grade is greater than 60 and “failed” otherwise.
Solution:-
 If student's grade is greater than or equal to 60
◦ Print "passed"
 else
◦ Print "failed“
Pseudo code
Example-2:
◦Pseudo-code the task of computing the final price of an item after
figuring in sales tax. Note the three types of instructions: input (get),
process/calculate (=) and output (display)
1. get price of item
2. get sales tax rate
3. sales tax = price of item times sales tax rate
4. final prince = price of item plus sales tax
5. display final price
6. stop
Pseudo code
Example-3:
 Write a program that obtains two integer numbers from the user.
It will print out the sum of those numbers.
1. Prompt the user to enter the first integer
2.Prompt the user to enter a second integer
3.Compute the sum of the two user inputs
4.Display an output prompt that explains the answer as the
sum
5.Display the result
Flow Chart
 A graphic representation of an algorithm,
 often used in the design phase of programming to work out the
logical flow of a program
Flow Chart
Flowchart Symbol
Flow Chart
Example 1:
• Draw flow chart of an algorithm to add two numbers and
display their result.
 Algorithm description
1. Read the two numbers (A and B)
2. Add A and B
3. Assign the sum of A and B to C
4. Display the result ( c)
Flow Chart
Flow Char is :
Start

Read A, B

C= A+B

Print C

End
Flow Chart
Example 2:
 Write an algorithm description and draw a flow chart to check
a number is negative or not.
 Algorithm description
1. Read a number x
2. If x is less than zero write a message negative else write a
message not negative
Flow Chart
Flow Char is :
Flow Chart
 Some times there are conditions in which it is necessary to
execute a group of statements repeatedly. Until some
condition is satisfied. This condition is called a loop.
 Loop is a sequence of instructions, which is repeated until
some specific condition occurs.
 A loop normally consists of four parts.
Flow Chart
 A loop normally consists of four parts. These are:
◦ Initialization: - Setting of variables of the computation to
their initial values and setting the counter for determining to
exit from the loop.
◦ Computation: - Processing
◦ Test: - Every loop must have some way of exiting from it or
else the program would endlessly remain in a loop.
◦ Increment: - Re-initialization of the loop for the next loop.
Flow Chart
Example -3:
 Write the algorithmic description and draw a flow chart to
find the following sum.
Sum = 1+2+3+…. + 50
 Algorithm description
1. Initialize sum to 0 and counter to 1
1.1. If the counter is less than or equal to 50
• Add counter to sum
• Increase counter by 1
 Repeat step 1.1
1.2. Else
• Exit
2. Write sum
Flow Chart
Flow Char is :
Structure Chart
 depicts the logical functions to the solution of the problem
using a chart.
 It provides an overview that confirms the solution to the
problem without excessive consideration to detail.
 It is high-level in nature.
Structure Chart
Example-1:
 Write a program that asks the user to enter a temperature
reading in centigrade and then prints the equivalent
Fahrenheit value.
Input Process Output
Centigrade  Prompt for centigrade value Fahrenheit
 Read centigrade value
 Compute Fahrenheit value
 Display Fahrenheit value
System Development Life
Cycle(SDLC)
 is a conceptual model used in project management that
describes the stages involved in a computer system
development project from an initial feasibility study through
maintenance of the completed application.
System Development Life
Cycle(SDLC)
 The phases of SDLC are :
 Feasibility study :
 Requirements analysis
 Designing solution
 Testing designed solution
 Testing
 Implementation
System Development Life Cycle
 Feasibility study : The first step is to identify a need for the
new system.
a. Organizational Feasibility
 How well the proposed system supports the strategic
objectives of the organization.
b. Economic Feasibility
 Cost savings
 Increased revenue
 Decreased investment
 Increased profits
System Development Life Cycle
c. Technical Feasibility
 Hardware, software, and network capability, reliability,
and availability
d. Operational Feasibility
 End user acceptance
 Management support
 Customer, supplier, and government requirements
System Development Life Cycle
Requirements analysis : is the process of analyzing the
information needs of the end users, the organizational
environment, and any system presently being used, developing
the functional requirements of a system that can meet the
needs of the users.
System Development Life Cycle
Designing solution:
 After the requirements have been determined, the necessary
specifications for the hardware, software, people, and data
resources, and the information products that will satisfy the
functional requirements of the proposed system can be
determined.
 The design will serve as a blueprint for the system and helps
detect problems before these errors or problems are built into
the final system.
System Development Life Cycle
Implementation
 The real code is written here. Systems implementation is the
construction of the new system and its delivery into
production or day-to-day operation.
System Development Life Cycle
Testing
◦ Unit Testing
◦ Integrating Testing
◦ System Testing
Maintenance
 What happens during the rest of the software's life: changes,
correction, additions, and moves to a different computing
platform and more.
 This, the least exciting and perhaps most important step of all,
goes on seemingly forever.
Assignment
1. Write the algorithmic description and draw a flowchart: If it is raining, tell
the user to get an umbrella. Otherwise, say it is sunny.
2. Write an algorithm and draw flowchart to read three numbers then display
the largest.
3. Write an algorithm and draw flow chart to find average age of a group of
10 players?
4. Draw Flowchart for the problem of printing odd numbers less than a given
number. It should also calculate their sum and count.
5.Draw Flowchart for the problem of printing even numbers between 9 and
100:
6. Draw flowchart to Convert temperature Fahrenheit to Celsius.
7.Draw flowchart to Find the area of a circle of radius r.
8. Write an algorithm description and draw the flowchart for finding factorial
of any given number

You might also like