Transcript CHAPTER 1

CHAPTER 2
SOFTWARE
DEVELOPMENT
METHOD
1
Objectives
In this chapter you will learn:
The electronic computers and its’
suitable programming language
To solve problem using problem-solving
strategies and methods
The algorithm as a guidance in
designing program
2
Subtopics
Electronic Computers
Introduction to Programming
Software Development Method
(SDM)
Algorithm Design
3
Electronic Computers
What is computer ?
 A computer is an electronic device
designed to perform operations specified
with a set of instructions called a program.
 A computer include both hardware &
software
4
Why we need computers ?
The use of Computer in daily activities
 bill payment, booking transportation ticket,
communication services, e-mailing friends, on-line
communication, subject registration, course
assessments & etc.
As for engineering students, you should develop
the ability to solve problems, and it is very likely
that you will need to use computers for problem
solving
5
Computer Hardware (1)
Major hardware components :

Central Processing Unit (CPU)





Control unit (CU) & Arithmetic/Logic Unit (ALU)
Memory (main memory)
Storage Devices (disks, CDs, tapes)
Input/Output Devices (monitors, keyboards, mice, printers
Communication Devices (modems and network interface
cards (NIC cards)
Note : The components are connected through a subsystem called a
bus that transfers data between the components.
(Source : Y.D. Liang “Introduction to Programming with C++”, Comprehensive
Version. International Edition. Pearson Education, 2007)
BEC 10102 SEM 1
6
Computer Hardware (2)
HARDWARE = PERIPHERAL EQUIPMENT
BEC 10102 SEM 1
+
CENTRAL/SYSTEM UNIT
7
Computer Software
Operating System (OS)
Unix, Window, Linux
Software Tools (Utility Packages)
o word processors (MicrosoftWord, WordPerfect)
o spreadsheet programs (Excel, Lotus1-2-3, ...)
Computer Languages/ Programming Languages
o machine language
o assembly language
o binary language
o high level languages (C, C++, Ada, Fortran,
Basic, java)
 User Developed Programs
o SMAP On-Line
o MayBank2you
8
Intro to Programming
Programming is the core of everything to do with
computers,
computing,
networked
systems,
management information systems, multimedia and
so on (all computer-based things)
Everything that runs on a computer is a program
and somebody (programmer) has to write it using
specific programming language. To understand
how computers can be used, how applications
work, how systems are configured, it is necessary for
you to understand what programs are and how
they are constructed.
BEC 10102 SEM 1
9
Software Development Method
(SDM)
What is Problem Solving@Solution ?
The process of transforming the description
of a problem into the solution of that
problem by using our knowledge of the
problem domain and by relying on our
ability to select and use appropriate
problem-solving strategies, techniques, and
tools.
10
SDM Phases
provides us with a precise definition of the
problem.
Requirement
Specification
 we identify problem inputs, outputs, constraints,
and formulas and equations to be used.
Analysis
Design
concerned with developing an
algorithm (subtopic 1.4) for the solution
of the problem.
Coding &
Implementation
Testing &
Verification
Documentation
& Maintenance
11
SDM : Coding & Implementation
Code the finalized algorithm using a suitable
programming language.
Go through the compiling & execution
process.
Normally, you will face this three types of
programming errors
Logic/Design errors
Syntax errors
Runtime errors
12
Logic/Design errors
o Design errors occur during the analysis, design,
and implementation phases.
o We may choose an incorrect method of solution
for the problem to be solved, we may make
mistakes in translating an algorithm into a
program, or we may design erroneous data for
the program.
o Design errors are usually difficult to detect.
o Debugging them requires careful review of
problem analysis, algorithm design, translation,
and test data.
13
Syntax Errors
o Syntax errors are violations of syntax rules, which
define how the elements of a programming
language must be written.
o They occur during the implementation phase
and are detected by the compiler during the
compilation process. In fact, another name for
syntax errors is compilation errors.
o If your program contains violations of syntax rules,
the compiler issues diagnostic messages.
o Depending on how serious the violation is, the
diagnostic message may be a warning message
or an error message.
14
Runtime Errors
o Run-time errors are detected by the computer
while your program is being executed.
o They are caused by program instructions that
require the computer to do something illegal,
such as attempting to store inappropriate data
or divide a number by zero.
o When a run-time error is encountered, the
computer produces an error diagnostic message
and terminates the program execution.
o You can use diagnostic messages to debug runtime errors.
15
SDM : Testing and Verification
• Testing the completed program to verify that it
works as desired.
• Do not rely on just one test case .
• Run the program several times using different
sets of data to make sure that it works correctly
for every situation provided in the algorithm.
BEC 10102 SEM 1
16
SDM : Documentation & Maintenance
For every problem solving, there are 5 things to be
documented :





Program description
Algorithm development and changes
Well-commented program listing
Sample test run
User’s manual
Maintenance is concerned with ongoing correction
of problems, revision to meet changing needs and
addition of new features. The better the documentation
is, the efficiently this phase can be performed.
17
Algorithm Design

An algorithm is a sequence of a finite
number of steps arranged in a specific
logical order that, when executed,
produces the solution for a problem.
 An algorithm design should be put on
paper. For this purpose, and also to
facilitate its development, we resort to
pseudocoding and flowcharting
18
Analogy
A) How to use ATM Machine ?
i. Step 1 ?
ii. Step 2 ?
……….
x. Final step ?
B) How to register courses using SMAP
on-line ?
19
Pseudocoding
Short English phrases with a limited
vocabulary are use to describe the
algorithm (the processing steps). A
pseudocode must :




have a limited vocabulary
be easy to learn
produce simple, English-like narrative notation
be capable of describing all algorithms,
regardless of their complexity
20
Example of Pseudocode
Problem 1 : (Sequence structure)
Compute total of resistor values.
Begin
read resistor1, resistor2
total = resistor1 + resistor2
print “ total “
End
21
Flowcharting
A graphical technique for algorithm
design and representation, is
equivalent to pseudocoding and
can be used as an alternative to it.
22
Flowchart Symbols (1)
Symbol
Name Of Symbol
Terminal
Input/Output
Description And
Example
Indicates the
beginning or end of
an algorithm
Indicates an Input
or Output operation
Process
Indicates
computation or data
manipulation
Decision
Indicates a decision
point in the
algorithm
23
Flowchart Symbols (2)
Symbol
Name Of Symbol
Description And
Example
Loop
Specific for for
statement
Indicates the initial, final
and increment values of a
loop.
Flow Lines/ Arrow
Used to connect the
symbols and indicates the
logic flow
On-Page Connector
Provides continuation of a
logical path on another
point in the same page.
Off-Page Connector
Provides continuation of a
logical path on another
page
24
Example of Flowchart
Problem 1 : (Sequence statements)
Compute total of resistor
values.
25
Pseudocode & Flowchart Convention
Sequence Structure
o a series of steps or statements that are
executed in order (ex : as shown in Problem 1)
Selection Structure
o Define two courses of action depending on
the outcome condition ( true or false)
Repetition control structures
oSpecifies a block of one or more statements
that are repeatedly executed until a condition
is satisfied.
26
Sequence Structure
begin
Statement_1
Statement_1
Statement_2
…
Statement_2
Statement_n
end
Statement_n
27
Selection Structure
•
Single Selection (if)
if condition
statement
condition
Yes
statement
yes
then_part
No
• Double Selection (if-else)
if condition
then_part
else
condition
no
else_part
else_part
end_if
BEC 10102 SEM 1
28
Repetition Structure
while condition
loop-body
condition
Yes
Loop_body
end_while
No
BEC 10102 SEM 1
29
Applying the SDM ( Phase 1 to 3)
Problem :
The C programming test scores can
be classified into two condition, PASS
and FAIL. The student is require to
input their marks in positive integer . If
the score is greater than or equal 50
message Pass will appear, message
Fail otherwise
30
Applying the SDM : Phase 1 & 2
Phase 1 : Requirement Specification
 Selection Structure
 test scores, message ‘PASS’, message ‘FAIL’, greater or
equal to 50, less than 50
Phase 2 :
Data requirements :
Input
:
test_score
Output
:
‘PASS’ or ‘FAIL’
Relevant formula : None
Constrain
:
the test score must greater than 0
(zero)
Condition
:
test_score >= 50
test_score < 50
31
Applying the SDM : Phase 3 (1)
Phase 3 : Design ( Pseudocode/Flowchart)
 Pseudocode
Begin
End
Read the test scores
Begin while
while test_score < 0
Print ‘ Re-enter your score and must greater than 0’
Read the test_score
End while
if test_score >= 50
print ‘PASS’
else
print ‘FAIL’
BEC 10102 SEM 1
32
Applying the SDM : Phase 3 (2)
 Flowchart
BEC 10102 SEM 1
33
Exercises
1. Write an algorithm (Pseudo code
and flow chart) for attending a
lecture
2. Write an algorithm that calculate
the multiplication of two integer
numbers.
3. Write an algorithm which can
determine the positive and
negative integer.
4. Write an algorithm that can print
series of odd numbers between 0
34
and 12.
Start
Wake Up
Take Shower
Get Dressed
Eat Breakfast
Walk to Lecture
hall
N
Has
Transport
Y
Go back
home
Y
Late?
Take Transport
N
End
Enter Class
35
Begin
Wake up
Take shower
Get dressed
Eat breakfast
If has transport
take transport
Else
walk to lecture hall
If late
go back home
Else
enter class
end
36
Begin
int w;
int l;
int area;
w=20;
l=25;
area=w*l
print “Your area is “
print area
end
37
–Write a program to calculate the
square area. Print area
–Design a Program that a salesperson
gets 6 percent commission on sales
less than $1000, 8 percent on sales in
the range $1000 through $2000, and
10 percent on sales in excess of
$2000. Print the commission.
38
• Write a program that can read age. Print
“young” if the age less than 20, print
“Adult” if the age between 20 to 30 and
print “old” if the age above 30.
39