προγραμματισμός εργαστήριο

  • Published on
    27-Oct-2015

  • View
    252

  • Download
    6

Embed Size (px)

DESCRIPTION

. !

Transcript

  • / I

    .

    , 2012

  • 2

    ,

    ,

    .

  • 3

    / 2

    ,

    2006-

    2007.

    .

    . .

    .

    .

    Fortran C++

    , , , ,

    / .

    C++

    ,

    .

    . ,

    ,

    . ,

    ,

    .

    .

    . .

    .

    .

    .

    .

    .

  • 4

    :

    .

    .

    .

    .

    . ,

    .

    .

    ,

    .

    .

    .

    . .

    . .

    1. oo vo o.

    2. o v v .

    3. Fortran

    Fortran .

    4.

    .

  • 5

    ___________________________________________________________________ 3

    ________________________________________________________________ 5

    1 ________________________________________________________________ 7 ___________________________________________________________ 7 . - _________________________________________ 7 . __________________________________________________________ 11 . _____________________________ 13

    2 ______________________________________________________________ 17 __________________________________________________________ 17 . - ________________________________________ 17 . __________________________________________________________ 19 . _____________________________ 21

    3 ______________________________________________________________ 25 __________________________________________________________ 25 . - ________________________________________ 25 . __________________________________________________________ 28 . _____________________________ 30

    4 ______________________________________________________________ 35 __________________________________________________________ 35 . - ________________________________________ 35 . __________________________________________________________ 38 . _____________________________ 40

    5 ______________________________________________________________ 45 __________________________________________________________ 45 . - ________________________________________ 45 . __________________________________________________________ 48 . _____________________________ 50

    6 ______________________________________________________________ 53 __________________________________________________________ 53 . - ________________________________________ 53 . __________________________________________________________ 56 . _____________________________ 59

    7 ______________________________________________________________ 65 __________________________________________________________ 65 . - ________________________________________ 65 . __________________________________________________________ 67 . _____________________________ 69

    8 ______________________________________________________________ 71 __________________________________________________________ 71 . - ________________________________________ 71 . __________________________________________________________ 73 . _____________________________ 74

    9 ______________________________________________________________ 77 __________________________________________________________ 77 . - ________________________________________ 77 . __________________________________________________________ 79 . _____________________________ 82

  • 6

    _______________________________________________________________ 85 __________________________________________________________ 85 Crimson G95 ________________________ 85

    ______________________________________________________________ 89 __________________________________________________________ 89 Crimson C++ _____________________ 89

    ______________________________________________________________ 93

  • 7

    1

    Fortran/C++ -

    :

    (Fortran

    C++),

    ,

    ,

    ,

    ,

    .

    .

    .

    Fortran :

    1.

    ;

    2. var12 VAR12.

    ;

    3. ;

    4. PROGRAM;

    5.

    Fortran;

    6.

    ; ;

    7. ;

    () PRINT*, GEIA () PRINT*, 'GEIA'

    8.

    . ;

    9. =+2;

    10. ;

    11. ; ;

    () PRINT*, 1/3 () PRINT*, 1./3.

  • 8

    12.

    G 9.81.

    13.

    INT .

    14. Fortran;

    ;

    15.

    ;

    16. ;

    17. ;

    18.

    , , ;

    19.

    A**B+(C+D)*E/F;

    20.

    ;

    . Fortran ( ).

    :

    ! First Program

    PROGRAM FIRST

    PRINT*,'A first program in Fortran'

    END PROGRAM FIRST

    .

    C++ :

    1. ;

    2. var12 VAR12.

    ;

    3. ;

    4. C++,

    ;

    5. C++;

    6.

    ; .

    ;

    7. ;

    () cout

  • 9

    9. =+2;

    10.

    ;

    11. C++;

    xy;

    12. #include

    C++;

    13.

    varint .

    ;

    14. C++;

    ;

    15. ( )

    ;

    16. int unsigned int;

    17.

    ;

    18. char;

    19. += ++;

    .

    20. var++ ++var;

    . C++ ( ).

    :

    // First program

    #include

    using namespace std;

    int main()

    {

    cout

  • 10

    E. []

    l

    glT 2 , l g

    .

    Fortran C++

    l

    9.81 m/s2.

    PROGRAM ekkremes

    REAL g,pi,t,l

    PARAMETER (pi=3.14159, g=9.81)

    PRINT*,'Dwste timh gia to l'

    READ*, l

    t = 2*pi*sqrt(l/g) ! Pendulum period evaluation

    PRINT*, 'The period of the pendulum is ', t

    STOP

    END PROGRAM ekkremes

    // pendulum

    #include

    #include

    using namespace std;

    int main()

    {

    const double PI = 3.14159;

    const double g = 9.81;

    double t, l;

    cout > l;

    t = 2*PI*sqrt(l/g);

    cout

  • 11

    3.

    .

    .

    .

    A. [ ]

    B

    , , ,

    ))()(( E , .

    (x1, y1) (x2, y2)

    2212

    21 )()( yyxxa .

    Fortran C++

    .

    , ,

    .

    .

    ! program triangle

    !

    REAL ax,ay,bx,by,cx,cy,sa,sb,sc,t,area !variable declaration

    PRINT, 'Give the coordinates of the triangle vertexes: '

    READ*, ax,ay,bx,by,cx,cy

    sc = sqrt((ax-bx)**2+(ay-by)**2) !Evaluation of one side

    t = (sa+sb+sc)/2

    area = sqrt(t*(t-sa)*(t-sb)*(t-sc)) !Area evaluation

    PRINT*, 'Area is: ', area

    STOP

    END

    // program triangle

    #include

    #include

    using namespace std;

    int main()

    {

    float ax, ay, bx, by, cx, cy;

    float sa, sb, sc, t, area;

    cout

  • 12

    cin >> ax >> ay >> bx >> by >> cx >> cy;

    sc = sqrt((ax-bx)*(ax-bx) +(ay-by)**2);

    t = (sa+sb+sc)/2

    area = sqrt(t*(t-a)*(t-b)*(t-c)); // Area evaluation

    cout

  • 13

    ()

    ,

    .

    .

    A. [ ]

    tAx 11

    )(22 tAx .

    : )( tAx ,

    212

    2

    2

    1 2 AAAAA

    21

    2

    .

    Fortran C++

    1 2. =0 =180.

    ;

    . [ ]

    .

    Bernoulli

    : ghv 2 .

    Torricelli:

    h

    h.

    h

    E

    K

    x x1 x2

  • 14

    Fortran C++

    h.

    .

    . [ Ventouri]

    A1

    A2

    1 2

    h

    1 2

    .

    1 2 h

    , v1

    A1 : 1)(

    22

    21

    1

    AA

    ghv .

    Fortran C++

    1 2 h.

    .

    . [ ]

    p m

    v : 22 /1 cv

    mvp

    , c .

    v ,

    : mvp .

    0 c v

    p

    Fortran C++

  • 15

    .

    .

    . [ () ]

    :

    , , r

    .

    v.

    v

    rg

    2

    )(9

    2 , g .

    Fortran C++

    . , , g, r v

    .

    .

    . [ ]

    1687

    :

    .

    F m1

    m2 d F=Gm1m2/d2,

    G=6.6710-11 Nm2kg-2 .

    Fortran C++

    m1 m2 d.

    m1, m2 d .

    Z. [ ]