0% found this document useful (0 votes)
33 views2 pages

Unit Interface Uses: /Desktop/Fungsi - Pas Page 1

This document contains the code for a Pascal program with a form that contains buttons and edits. It defines a function f(x) that calculates x squared. When button1 is clicked, it takes the value from edit1, calculates f(x), displays the result in edit2 and plots the graph of y=f(x) on the image.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Unit Interface Uses: /Desktop/Fungsi - Pas Page 1

This document contains the code for a Pascal program with a form that contains buttons and edits. It defines a function f(x) that calculates x squared. When button1 is clicked, it takes the value from edit1, calculates f(x), displays the result in edit2 and plots the graph of y=f(x) on the image.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

~/Desktop/fungsi.

pas Page 1

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Image1: TImage;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
function f(x:real):real;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function tform1.f(x:real):real;
begin
f:= x*x;
end;

procedure TForm1.FormCreate(Sender: TObject);


begin
button1.Caption:='OK';
button2.Caption:='fungsi y = x';
button3.Caption:='fungsi y = −2x';
button4.Caption:='fungsi y = sin (x)';
button5.Caption:='fungsi y = sin (3x)';
button6.Caption:='fungsi y = sin (x) + x';

edit1.Text:='0';
edit2.Text:='';
end;

procedure TForm1.Button1Click(Sender: TObject);


var x,y:real;
i,x0,y0:integer;
begin
x:=strToFloat(edit1.Text);
y:=f(x);
edit2.Text:=floatToStr(y);
//gambar
x0:=image1.Width div 2;
y0:=image1.Height div 2;
image1.Canvas.Pen.Color:=clLime;
image1.Canvas.MoveTo(0,y0);
image1.Canvas.LineTo(image1.Width,y0);
image1.Canvas.Pen.Color:=clBlue;
image1.Canvas.MoveTo(x0,0);
image1.Canvas.LineTo(x0,image1.Height);
for i:=−100 to 100 do begin
x:=i/10;
y:=f(x);
image1.Canvas.Pixels[x0+i,y0−round(y)]:=clRed;
end;
~/Desktop/fungsi.pas Page 2

end;

end.

You might also like