• Penggunaan Array di Free Pascal Compiler (Lazarus)

    by  • July 21, 2013 • Lazarus, Pemrograman Komputer

    Dengan menggunakan Lazarus, kita dapat membuat program atau code Pascal.

    Untuk contoh perhitungan bidang momen dan lintang dengan menggunakan Array dapat dilihat pada code berikut,

    program Project1;

    {$mode objfpc}{$H+}

    uses
    {$IFDEF UNIX}{$IFDEF UseCThreads}
    cthreads,
    {$ENDIF}{$ENDIF}
    Classes
    { you can add units after this };

    {$R *.res}

    type
    hasil = array [1..101] of real;

    var
    Fileout : text ;
    i : integer ;
    x,Va : real ;
    Dmx,Ddx : hasil;

    begin
    assign(fileout,’momen.txt’);
    rewrite(fileout);
    for i := 1 to 101 do
    begin
    x := real (i-1);
    Va := 13.5 ;
    if x <= 50 then
    begin
    Dmx[i] := Va*x ;
    Ddx[i] := Va ;
    writeln(fileout,’ x = ‘,x:5:2,’ Dmx= ‘,Dmx[i]:5:2, ‘ Ddx= ‘,Ddx[i]:5:2);
    end;
    if x >= 50 then
    begin
    Dmx[i] := (Va*x) – (2*(x-50))-(0.5*1*(x-50)*(x-50));
    Ddx[i] := Va-2-(1*(x-50));
    writeln(fileout,’ x = ‘,x:5:2,’ Dmx= ‘,Dmx[i]:5:2, ‘ Ddx= ‘,Ddx[i]:5:2);
    end;
    end;
    close (fileout);

    end.

    Pascal code di atas merupakan isi dari file “project1.lpr.”

    Hasil perhitungan ditulis ke dalam file “momen.txt”. Isi dari file ini dapat dilihat sebagai berikut,

    x = 0.00 Dmx= 0.00 Ddx= 13.50
    x = 1.00 Dmx= 13.50 Ddx= 13.50
    x = 2.00 Dmx= 27.00 Ddx= 13.50
    x = 3.00 Dmx= 40.50 Ddx= 13.50
    x = 4.00 Dmx= 54.00 Ddx= 13.50
    x = 5.00 Dmx= 67.50 Ddx= 13.50
    x = 6.00 Dmx= 81.00 Ddx= 13.50
    x = 7.00 Dmx= 94.50 Ddx= 13.50
    x = 8.00 Dmx= 108.00 Ddx= 13.50
    x = 9.00 Dmx= 121.50 Ddx= 13.50
    x = 10.00 Dmx= 135.00 Ddx= 13.50
    x = 11.00 Dmx= 148.50 Ddx= 13.50
    x = 12.00 Dmx= 162.00 Ddx= 13.50
    x = 13.00 Dmx= 175.50 Ddx= 13.50
    x = 14.00 Dmx= 189.00 Ddx= 13.50
    x = 15.00 Dmx= 202.50 Ddx= 13.50
    x = 16.00 Dmx= 216.00 Ddx= 13.50
    x = 17.00 Dmx= 229.50 Ddx= 13.50
    x = 18.00 Dmx= 243.00 Ddx= 13.50
    x = 19.00 Dmx= 256.50 Ddx= 13.50
    x = 20.00 Dmx= 270.00 Ddx= 13.50
    x = 21.00 Dmx= 283.50 Ddx= 13.50
    x = 22.00 Dmx= 297.00 Ddx= 13.50
    x = 23.00 Dmx= 310.50 Ddx= 13.50
    x = 24.00 Dmx= 324.00 Ddx= 13.50
    x = 25.00 Dmx= 337.50 Ddx= 13.50
    x = 26.00 Dmx= 351.00 Ddx= 13.50
    x = 27.00 Dmx= 364.50 Ddx= 13.50
    x = 28.00 Dmx= 378.00 Ddx= 13.50
    x = 29.00 Dmx= 391.50 Ddx= 13.50
    x = 30.00 Dmx= 405.00 Ddx= 13.50
    x = 31.00 Dmx= 418.50 Ddx= 13.50
    x = 32.00 Dmx= 432.00 Ddx= 13.50
    x = 33.00 Dmx= 445.50 Ddx= 13.50
    x = 34.00 Dmx= 459.00 Ddx= 13.50
    x = 35.00 Dmx= 472.50 Ddx= 13.50
    x = 36.00 Dmx= 486.00 Ddx= 13.50
    x = 37.00 Dmx= 499.50 Ddx= 13.50
    x = 38.00 Dmx= 513.00 Ddx= 13.50
    x = 39.00 Dmx= 526.50 Ddx= 13.50
    x = 40.00 Dmx= 540.00 Ddx= 13.50
    x = 41.00 Dmx= 553.50 Ddx= 13.50
    x = 42.00 Dmx= 567.00 Ddx= 13.50
    x = 43.00 Dmx= 580.50 Ddx= 13.50
    x = 44.00 Dmx= 594.00 Ddx= 13.50
    x = 45.00 Dmx= 607.50 Ddx= 13.50
    x = 46.00 Dmx= 621.00 Ddx= 13.50
    x = 47.00 Dmx= 634.50 Ddx= 13.50
    x = 48.00 Dmx= 648.00 Ddx= 13.50
    x = 49.00 Dmx= 661.50 Ddx= 13.50
    x = 50.00 Dmx= 675.00 Ddx= 13.50
    x = 50.00 Dmx= 675.00 Ddx= 11.50
    x = 51.00 Dmx= 686.00 Ddx= 10.50
    x = 52.00 Dmx= 696.00 Ddx= 9.50
    x = 53.00 Dmx= 705.00 Ddx= 8.50
    x = 54.00 Dmx= 713.00 Ddx= 7.50
    x = 55.00 Dmx= 720.00 Ddx= 6.50
    x = 56.00 Dmx= 726.00 Ddx= 5.50
    x = 57.00 Dmx= 731.00 Ddx= 4.50
    x = 58.00 Dmx= 735.00 Ddx= 3.50
    x = 59.00 Dmx= 738.00 Ddx= 2.50
    x = 60.00 Dmx= 740.00 Ddx= 1.50
    x = 61.00 Dmx= 741.00 Ddx= 0.50
    x = 62.00 Dmx= 741.00 Ddx= -0.50
    x = 63.00 Dmx= 740.00 Ddx= -1.50
    x = 64.00 Dmx= 738.00 Ddx= -2.50
    x = 65.00 Dmx= 735.00 Ddx= -3.50
    x = 66.00 Dmx= 731.00 Ddx= -4.50
    x = 67.00 Dmx= 726.00 Ddx= -5.50
    x = 68.00 Dmx= 720.00 Ddx= -6.50
    x = 69.00 Dmx= 713.00 Ddx= -7.50
    x = 70.00 Dmx= 705.00 Ddx= -8.50
    x = 71.00 Dmx= 696.00 Ddx= -9.50
    x = 72.00 Dmx= 686.00 Ddx= -10.50
    x = 73.00 Dmx= 675.00 Ddx= -11.50
    x = 74.00 Dmx= 663.00 Ddx= -12.50
    x = 75.00 Dmx= 650.00 Ddx= -13.50
    x = 76.00 Dmx= 636.00 Ddx= -14.50
    x = 77.00 Dmx= 621.00 Ddx= -15.50
    x = 78.00 Dmx= 605.00 Ddx= -16.50
    x = 79.00 Dmx= 588.00 Ddx= -17.50
    x = 80.00 Dmx= 570.00 Ddx= -18.50
    x = 81.00 Dmx= 551.00 Ddx= -19.50
    x = 82.00 Dmx= 531.00 Ddx= -20.50
    x = 83.00 Dmx= 510.00 Ddx= -21.50
    x = 84.00 Dmx= 488.00 Ddx= -22.50
    x = 85.00 Dmx= 465.00 Ddx= -23.50
    x = 86.00 Dmx= 441.00 Ddx= -24.50
    x = 87.00 Dmx= 416.00 Ddx= -25.50
    x = 88.00 Dmx= 390.00 Ddx= -26.50
    x = 89.00 Dmx= 363.00 Ddx= -27.50
    x = 90.00 Dmx= 335.00 Ddx= -28.50
    x = 91.00 Dmx= 306.00 Ddx= -29.50
    x = 92.00 Dmx= 276.00 Ddx= -30.50
    x = 93.00 Dmx= 245.00 Ddx= -31.50
    x = 94.00 Dmx= 213.00 Ddx= -32.50
    x = 95.00 Dmx= 180.00 Ddx= -33.50
    x = 96.00 Dmx= 146.00 Ddx= -34.50
    x = 97.00 Dmx= 111.00 Ddx= -35.50
    x = 98.00 Dmx= 75.00 Ddx= -36.50
    x = 99.00 Dmx= 38.00 Ddx= -37.50
    x = 100.00 Dmx= 0.00 Ddx= -38.50

    Code lengkap dari penggunaan array dapat dilihat pada file ini