lec1_sdm

Upload: sathia-raj

Post on 09-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Lec1_SDM

    1/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 1

    CHAPTER 1

    SOFTWAREDEVELOPMENT

    METHOD

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 2

    Objectives

    In this c ha pter you will lea rn:

    The elec tronic c omputers and itssuitab le p rog ramming langua ge

    To solve p rob lem using p rob lem-solvingstra teg ies and method s

    The a lgorithm as a guidanc e in

    designing p rog ram

  • 8/7/2019 Lec1_SDM

    2/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 3

    Subtop ic s

    Elec tronic Com puters

    Introd uc tion to Programming

    Software Development Method(SDM)

    Algorithm Design

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 4

    Elec tronic ComputersWhat is c omp uter ?

    A computer is an electronic device

    designed to perform operations specifiedwith a set of instruc tions c a lled a program.

    A computer include both hardware &software

  • 8/7/2019 Lec1_SDM

    3/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 5

    Why we need c omputers ?

    The use of Computer in da ily ac tivities bill payment, booking transportation ticket,communication services, e-mailing friends, on-linecommunication, subject registration, courseassessments & etc .

    As for engineering students, you should developthe ability to solve problems, and it is very likelythat you will need to use computers for problemsolving

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 6

    Computer Hardware (1)Ma jor hardware components :

    Ce ntra l Proc essing Unit (CPU)

    Co ntrol unit (CU) & Arithme tic / Log ic Unit (ALU)

    Memory (main memory)

    Sto rage Devices (disks, CDs, tapes)

    Input/Output Devices (monitors, keyboards, mice, printers

    Com munic ation Devic es (mode ms and netwo rk interfac ec ards (NIC c ards)

    Note : The c om po nents are c onnec ted through a subsystem ca lled a

    busthat transfers da ta betwe en the co mpo nents.

    (Sourc e :Y.D. Liang Introduction to Programming with C++, Comprehensive

    Version. International Edition. Pearson Education, 2007)

  • 8/7/2019 Lec1_SDM

    4/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 7

    Computer Hardware (2)

    HARDWARE = PERIPHERAL EQUIPMENT + CENTRAL/ SYSTEM UNIT

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 8

    Computer Softwa reOperating System (OS)

    Unix, Window, Linux

    Softwa re Too ls (Utility Pac ka ge s)

    o word processors (MicrosoftWord, WordPerfect)o spreadsheet programs (Excel, Lotus1-2-3, ...)

    Com puter Lang uag es/ Programm ing Lang uageso mac hine language

    o assembly languageo binary languag e

    o high level lang uag es (C, C++, Ada, Fortran,Basic, java )

    User Develop ed Program s

    o SMAP On-Lineo MayBank2you

  • 8/7/2019 Lec1_SDM

    5/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 9

    Intro to Programming

    Programming is the core of everything to do withcomputers, computing, networked systems,management information systems, multimedia andso o n (a ll comp uter-based things)

    Everything that runs on a computer is a programand someb ody (programmer) has to write it usingspecific programming language. To und ersta ndhow computers can be used, how applicationswo rk, how systems are configured , it is necessary fo r

    you to understand what programs are and howthey a re c onstruc ted .

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 10

    Software Develop ment Me thod(SDM)

    What is Prob lem Solving@Solution ?

    The process of transforming the descriptionof a problem into the solution of thatproblem by using our knowledge of theproblem domain and by relying on our

    ability to select and use app ropria te problem-solving strategies, techniques, and tools.

  • 8/7/2019 Lec1_SDM

    6/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 11

    SDM Phases

    provides us with a precise definition of theproblem.

    we identify problem inputs, outputs, constraints,and formulas and equations to be used.

    concerned with developing analgorithm (subtopic 1.4) for the solutionof the problem.

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 12

    SDM : Coding & Implementation

    Code the finalized a lgo rithm using a suitableprogramming language .

    Go through the compiling & executionprocess.

    Norma lly, you w ill face this three types ofprog ramm ing errors

    Log ic/ Design errors

    Syntax errorsRuntime errors

  • 8/7/2019 Lec1_SDM

    7/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 13

    Logic / Design errors

    o Design errors occur during the analysis, design,and implementation phases.

    o We m ay c hoose a n inco rrec t me thod of solutionfor the problem to be solved, we may makemistakes in translating an algorithm into aprogram, or we may design erroneous data forthe program .

    o Design e rrors a re usua lly difficult to d etec t.

    o Debugging them req uires ca reful review of

    problem analysis, algorithm design, translation,and test da ta.

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 14

    Syntax Errors

    o Syntax errors are violations of syntax rules, whichdefine how the elements of a programminglang uag e m ust be w ritten.

    o They oc cur during the implementation phaseand are detected by the compiler during thecompilation process. In fact, another name forsyntax errors is com pilation errors.

    o If your prog ram c onta ins violations of synta x rules,

    the com piler issues diagnostic messages.o Depend ing on ho w serious the violation is, thediag nostic messag e m ay be a wa rning messag eor an error me ssage.

  • 8/7/2019 Lec1_SDM

    8/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 15

    Runtime Errors

    o Run-time e rrors are detec ted by the com puterwhile your prog ram is being exec uted .

    o They a re c aused by program instruc tions tha trequire the c om pute r to do som ething illegal,such as attemp ting to store inap propria te d ataor divide a numb er by zero.

    o When a run-time error is enc ounte red , thecom puter p rod uces an error d iagnostic messageand terminates the p rog ram exec ution.

    o You c an use d iagnostic messag es to d eb ug run-time errors.

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 16

    SDM : Testing and Verification

    Testing the c omp leted program to verify that itworks as desired .

    Do not rely on just one test case .

    Run the prog ram several times using differentsets of data to ma ke sure tha t it works correc tly

    for every situa tion provided in the a lgorithm.

  • 8/7/2019 Lec1_SDM

    9/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 17

    SDM : Doc umentation & Maintena nce

    For eve ry p rob lem solving, the re a re 5 things to b e

    doc umented : Program desc ription

    Algorithm developme nt and c hanges

    Well-commented program listing

    Samp le test run

    Users ma nua l

    Maintenance is c onc erned with ongo ing c orrec tionof problems, revision to meet changing needs andadd ition of new fea tures. The be tter the doc umentation

    is, the e ffic iently this pha se c an be pe rformed .

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 18

    Algorithm Design An a lgorithm is a sequence o f a finite

    number of steps arranged in a spec ific

    log ical order that, when exec uted ,

    produces the solution for a p rob lem .

    An a lgo rithm design should b e p ut on

    paper. For this purpose, and a lso to

    fac ilita te its deve lop ment, we resort topseudocoding and flowcharting

  • 8/7/2019 Lec1_SDM

    10/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 19

    Analogy

    A) How to use ATM Mac hine ?i. Step 1 ?ii. Step 2 ?.x. Fina l step ?

    B) How to reg iste r c ourses using SMAP

    on-line ?

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 20

    Pseudocoding

    Short Eng lish p hrases with a limited

    voc abulary are use to d esc ribe the

    a lgorithm (the proc essing steps). A

    pseudoc ode must :

    have a limited voc abulary

    be easy to learn prod uc e simp le, Eng lish-like na rra tive no ta tion

    be cap ab le of d esc ribing a ll algo rithms,

    reg ard less of their com plexity

  • 8/7/2019 Lec1_SDM

    11/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 21

    Example of Pseudocode

    Prob lem 1 : (Seq uenc e struc ture)

    Compute to ta l of resistor va lues.

    Begin

    rea d resisto r1, resisto r2

    total = resistor1 + resistor2

    print total

    End

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 22

    Flowcharting

    A graphic a l tec hnique for a lgorithmdesign and rep resenta tion, isequivalent to pseudoc od ing andc an be used as an a lterna tive to it.

  • 8/7/2019 Lec1_SDM

    12/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 23

    Flowcha rt Symbols (1)

    Indicates a decisionpoint in thealgorithm

    Decision

    Indicatescomputation or datamanipulation

    Process

    Indicates an Inputor Output operationInput/Output

    Indicates thebeginning or end ofan algorithm

    Terminal

    Description AndExample

    Name Of SymbolSymbol

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 24

    Flowchart Symbols (2)Description AndExample

    Name Of SymbolSymbol

    Provides continuation of alogical path on anotherpage

    Off-Page Connector

    Provides continuation of alogical path on another

    point in the same page.

    On-Page Connector

    Used to connect thesymbols and indicates thelogic flow

    Flow Lines/ Arrow

    Specific for forstatement

    Indicates the initial, final

    and increment values of aloop.

    Loop

  • 8/7/2019 Lec1_SDM

    13/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 25

    Example of Flowchart

    Problem 1 : (Sequence statements)

    Compute total of resistor

    values.

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 26

    Pseudoc od e & Flow c hart Convention

    Sequence Structure

    o a series of step s or sta tem ents tha t a reexec uted in order (ex : as shown in Prob lem 1)

    Selec tion Structure

    o Define two c ourses of ac tion de pending onthe outcom e c ond ition ( true or fa lse)

    Repetition c ontrol struc tures

    o Spec ifies a b loc k of one or mo re sta tem entsthat a re rep ea ted ly exec uted until a c ond itionis sa tisfied .

  • 8/7/2019 Lec1_SDM

    14/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 27

    Sequenc e Struc ture

    begin

    Statement_1

    Statement_2

    Statement_n

    end

    Statement_1

    Statement_2

    Statement_n

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 28

    Selec tion Struc ture

    Single Selection (if)

    if condition

    statement

    if condition

    then_part

    else

    else_part

    end_if

    Double Selection (if-else)

    condition statement

    No

    Yes

    condition then_part

    else_part

    no

    yes

  • 8/7/2019 Lec1_SDM

    15/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 29

    Repetition Struc ture

    while condition

    loop-body

    end_while

    condition Loop_body

    No

    Yes

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 30

    Ap p lying the SDM ( Pha se 1 to 3)

    Problem :

    The C programming test sc ores c anbe c lassified into two c ond ition, PASSand FAIL. The student is require toinput the ir ma rks in p ositive integer . Ifthe sc ore is g rea ter than or eq ua l 50message Pass will appear, messageFail otherwise

  • 8/7/2019 Lec1_SDM

    16/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 31

    Ap p lying the SDM : Phase 1 & 2

    Phase 1 : Requirement Spec ification Selec tion Struc ture

    test sc ores, me ssage PASS , message FAIL , grea te r orequal to 50, less than 50

    Phase 2 :Data req uirem ents :

    Input : test_scoreOutp ut : PASS or FAILReleva nt formula : None

    Co nstrain : the test score must g rea ter tha n 0(zero)

    Cond itio n : test_sc ore >= 50test_score < 50

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 32

    Applying the SDM : Phase 3 (1)

    Phase 3 : Design ( Pseudocode/Flowchart)

    Pseudocode

    Begin

    Rea d the te st sc ores

    Beg in while

    while test_score < 0Print Re-ente r your sc ore and m ust greate r than 0

    Read the test_score

    End whileif test_sc ore >= 50

    print PASS

    else

    print FAILEnd

  • 8/7/2019 Lec1_SDM

    17/17

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 33

    Applying the SDM : Phase 3 (2)

    Flowchart

    BEC 10102 SEM 1 2010/2011BEC 10102 SEM 1 2010/2011 34

    Exercises1. Write an a lgo rithm tha t ca lc ulate

    the multiplication of two integernumbers.

    2. Write an algo rithm whic h c andetermine the positive andnegative integer.

    3. Write an algo rithm tha t can printseries of odd numb ers betw een 0and 12.