structure diagram (1)

Upload: angcw

Post on 28-Feb-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Structure Diagram (1)

    1/20

    StructureStructure

    DiagramDiagram

  • 7/25/2019 Structure Diagram (1)

    2/20

    Example of programExample of program#include

    #include

    /* Define complex double data type */

    //typedef complex dcomp;

    int main()

    {

    dcomp i, a, b, c, d, e, p, , !;

    // Decla!e complex double "a!iables double x, y;

    /* et complex double "a!iable

    eual to complex double constant */

    i $ dcomp (%., &.);

    p!intf('ni $ (.+f, .+f)n', i);

    /* est a!ithmetic ope!ations -ith

    complex double "a!iables */

    a $ i * i;

    b $ &. / i;

    p!intf('ni*i $ (.+f, .+f)n', a);

    p!intf('&/i $ (.+f, .+f)n', b);

    /* est mathematical functions usin complex

    double "a!iables */

    c $ s!t(i); d $ sin(i);

    e $ po-(i, %.0);

    p!intf('ns!t(i) $ (.+f, .+f)n', c);

    p!intf('sin(i) $ (.+f, .+f)n', d);

    p!intf('i1%.0 $ (.+f, .+f)n', e);

    /* est complex ope!ations */ p $ con2(i);

    $ !eal(i);

    ! $ ima(i);

    p!intf('ncon2(i) $ (.+f, .+f)n', p);

    p!intf('!eal(i) $ .+fn', );

    p!intf('ima(i) $ .+fn', !);

    !etu!n %;

    3

  • 7/25/2019 Structure Diagram (1)

    3/20

    Flow ChartsFlow Charts

    4 flo-cha!t is a4 flo-cha!t is a

    !aphical method of!aphical method of

    desc!ibin andesc!ibin an

    alo!ithm.alo!ithm.

    o see the o"e!allo see the o"e!all

    flo- of loicflo- of loic

  • 7/25/2019 Structure Diagram (1)

    4/20

    SymbolsSymbols

    Decision

    (loop, selection)

    Input / utputInternal process

    Function

    Start/En!

    connector

  • 7/25/2019 Structure Diagram (1)

    5/20

    "inclu!e #st!io$h%

    int main()

    &

    int number, a,b'*

    printf(+Enter a number +)*

    scanf(+-!+, .number)*

    a ' number b*

    printf(+a is -!0n+, a)*

    return *

    1

    Structure 2rogram IStructure 2rogram I

    Start

    Total = Number + 10

    End

    Request user

    enter number

    Print total num

  • 7/25/2019 Structure Diagram (1)

    6/20

    "inclu!e#st!io$h%

    3oi! main()

    &

    float si!e, perimeter, area*

    si!e ' 4$5* perimeter ' 6$7 8 si!e*

    area ' si!e 8 si!e*

    printf(+Si!e -$4f0n+, si!e)*

    printf(+2erimeter -$5f0n+, perimeter)* printf(+9rea -$f0n+, area)*

    1

    Structure 2rogram IIStructure 2rogram II

    Start

    End

    Print value of side,

    perimeter and area

    Declaration and

    initialiation for side,

    perimeter and area

  • 7/25/2019 Structure Diagram (1)

    7/20

    "inclu!e#st!io$h%

    int main(3oi!)

    &

    int score*

    printf(+Insert the amount of score 0n+)*

    scanf(+-!+, .score)*

    if (score %' :)

    &

    printf (+Congratulations;0n+)*

    1

    printf (+

  • 7/25/2019 Structure Diagram (1)

    8/20

    int main(3oi!)

    &

    int score*

    char gra!e*

    printf(+Insert the amount of score 0n+)*

    scanf(+-!+, .score)*

    if (score %' :)&

    gra!e ' =2=*

    printf (+Congratulations; 0n+)*

    1

    else

    & gra!e ' =F=*

    1

    printf (+

  • 7/25/2019 Structure Diagram (1)

    9/20

    printf(+Input three integers+)*

    scanf(+-!-!-!+, .x, .y, .>)*

    if (x#y)

    &

    min ' x*

    1

    else

    &

    min ' y*

    1

    if (> # min)&

    min ' >*

    1

    printf(+?he minimum 3alue is

    -!0n+, min)*

    request ' inte$ers input

    () * %# Noes

    print minvalue

    ( *

    min#

    min = %min = )

    min =

    es

    No

    Selection 2rogram (IF)Selection 2rogram (IF)5!o!am6+7&&(p0).doc

    http://program/L4_11(pg65).dochttp://program/L4_11(pg65).doc
  • 7/25/2019 Structure Diagram (1)

    10/20

    Selection 2rogram (IF)Selection 2rogram (IF)5!o!am6+7&(p).doc

    if (score %' @:)

    &gra!e ' =9=*

    1

    else if (score %' @)

    &gra!e ' =A=*

    1

    else if (score %' B)

    & gra!e ' =C=*

    1

    else

    &

    gra!e ' =F=*

    1

    Score !

    -" #

    No.rade = /

    Score !

    -0 #

    .rade =

    Score !

    0 #

    .rade = 2 .rade = &

    Print score and $rade

    es

    es

    No

    No

    es

    http://program/L4_12(pg66).dochttp://program/L4_12(pg66).doc
  • 7/25/2019 Structure Diagram (1)

    11/20

    Selection 2rogram (switch)Selection 2rogram (switch)printf(+Enter a number0n+)*

    scanf(+-!+, .n)*

    switch (n) &

    case

    printf(+ne0n+)*

    brea*

    case 5

    printf(+?wo0n+)*

    brea*case 4

    printf(+?hree0n+)*

    brea*

    Request user to input c3oice

    23oice#

    2ase 1

    Print

    one

    Print

    t4o

    Print

    t3ree

    2ase 5 2ase ' 2ase 6 2ase "

    Print

    four

    Print

    five

    default

    7nvalid

    input

    case 6

    printf(+Four0n+)*

    brea*case :

    printf(+Fi3e0n+)*

    brea*

    !efault

    printf(+In3ali! number;0n+)*

    1

  • 7/25/2019 Structure Diagram (1)

    12/20

    a3e a try;;

  • 7/25/2019 Structure Diagram (1)

    13/20

    9uestion : t!y this9uestion : t!y this#include

    void main()

    {

    int choice;

    printf(Welcome to add subtract calculator program\n);

    printf(!lease choose one of the follo"ing\n);

    printf(. add t"o numbers\n);

    printf($. substract t"o numbers\n);

    printf(%. e&it\n);printf('our choice \n);

    scanf(d*+choice);

    s"tich(choice)

    {

    case add();

    brea,;

    case $

    substract();

    brea,;

    case %

    printf(-han,s for testing m' program\n);

    brea,;

    /return 0;

  • 7/25/2019 Structure Diagram (1)

    14/20

    Iteration 2rogramIteration 2rogram#include

    int main ("oid){

    int data, sum$%;

    scanf('d', data);

    -hile (data >$ %)

    {

    sum =$ data;

    scanf('d', data);

    3

    p!intf ('he sum is dn', sum);

    !etu!n (%);

    3

    Start

    End

    Request user to input data

    Declaration for data and sum = 0

    Data ! =

    0#

    Sum = sum + data

    Request user to input data

    Print sum

    es

    No

  • 7/25/2019 Structure Diagram (1)

    15/20

    Iteration 2rogramIteration 2rogram

    printf(+ow many numbers you wish to enter +)*scanf (+-!+, .n)*

    printf(+0nEnter -! !ecimal numbers+,n)*

    !o &

    scanf (+-!+, .x)*

    if (max # x)

    &

    max ' x*

    1

    cnt*

    1 while (cnt # n)*

    printf (+0naximum 3alue -!0n+, max)*

    Request user to input

    amount of loopin$ (n

    8a) *

    data #

    8a) = data

    Print 8a) value

    es

    Request user input data

    2ount *

    n #

    2nt + 1

    es No

    No

  • 7/25/2019 Structure Diagram (1)

    16/20

    Simple FunctionSimple Function

    "inclu!e#st!io$h%

    3oi! prnGmessage()

    &

    printf(+0ta3e a nice !ay;0n+)*

    1

    int main(3oi!)

    &

    int n*

    printf(+?here is a message for you, 0n+)*

    prnGmessage()*

    return ()*

    1

    Start

    Declaration for n

    Print messa$e

    Print messa$e function

    End

    Start

    Print 3ave a nice da%

    End

    Functionprogram

    ainprog

  • 7/25/2019 Structure Diagram (1)

    17/20

    unctionunction

    3oi! prnGmessage(int )

    &

    int i*

    printf (+ere is the message0n+)*

    for (i ' * i #* i)

    printf (+ a3e a nice !ay;0n+)*1

    int main (3oi!)

    &

    int n*

    printf (+?here is a message for you$ 0n+)*

    printf (+ow many times !o you want to see it+)*

    scanf (+-!+, .n)*

    prnGmessage(n)*

    return ()*

    1

    Function

    program

    ain

    program

  • 7/25/2019 Structure Diagram (1)

    18/20

    ?ain p!o!am?ain p!o!am

    int main (3oi!)

    &

    int n*

    printf (+?here is a message for you$ 0n+)*

    printf (+ow many times you want tosee+)*

    scanf (+-!+, .n)*

    prnGmessage(n)*

    return ()*

    1

    Start

    Declaration for n

    Request user input n

    Print messa$e function

    End

  • 7/25/2019 Structure Diagram (1)

    19/20

    unction p!o!amunction p!o!am

    End

    i * end of

    loop#

    es

    print 93ave a nice da%:

    i ++

    Start

    Declaration for i

    Print messa$e

    No

    3oi! prnGmessage(int )

    &

    int i*

    printf (+ere is the message0n+)*

    for (i ' * i #* i)

    printf (+ a3e a nice !ay;0n+)*

    1

  • 7/25/2019 Structure Diagram (1)

    20/20

    2ractical time;;