0% found this document useful (0 votes)
47 views14 pages

Nama: Lifityani Nim:105090400111038 Tugas: Algoritma Dan Pemograman

This document describes a program for subtracting polynomials using linked lists. It includes the code for defining the data type and linked list structure. It also includes procedures for adding terms to each polynomial list, subtracting the lists to create a third list, and displaying the polynomials and results. Screenshots of the program form and output are also mentioned.

Uploaded by

Fadila Syukriah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views14 pages

Nama: Lifityani Nim:105090400111038 Tugas: Algoritma Dan Pemograman

This document describes a program for subtracting polynomials using linked lists. It includes the code for defining the data type and linked list structure. It also includes procedures for adding terms to each polynomial list, subtracting the lists to create a third list, and displaying the polynomials and results. Screenshots of the program form and output are also mentioned.

Uploaded by

Fadila Syukriah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Nama : Lifityani Nim :105090400111038 Tugas : ALGORITMA DAN PEMOGRAMAN

1. Program(Linked list) pengurangan polynomial unit Unit1;

interface

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

type data=^list; list = record angka:integer;

berikut:data; end; TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Label3: TLabel; Button1: TButton; Button2: TButton; ListBox1: TListBox; ListBox2: TListBox; ListBox3: TListBox; Button3: TButton; Button4: TButton; Button5: TButton; Label4: TLabel; Button6: TButton;

Label5: TLabel; Label6: TLabel; Label7: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; i,x,j : integer;

awalh, akhirh,awalp, akhirp,awalq, akhirq, baru, ptrsementara : data; implementation

{$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if edit1.text='' then x:= 0 else x:=strtoint (edit1.Text); new(baru); baru^.angka:=x; if awalp= nil then awalp := baru else akhirp^.berikut:=baru; akhirp:=baru; akhirp^.berikut:=nil; Edit1.Clear;

Edit1.SetFocus; ListBox1.Items.Add(intTostr(x)); end;

procedure TForm1.Button2Click(Sender: TObject); begin if edit2.text='' then x:= 0 else x:=strtoint (edit2.Text); new(baru); baru^.angka:=x; if awalq= nil then awalq := baru else akhirq^.berikut:=baru; akhirq:=baru; akhirq^.berikut:=nil; Edit2.Clear; Edit2.SetFocus;

ListBox2.Items.Add(intTostr(x)); end;

procedure TForm1.Button3Click(Sender: TObject); var p,q:data; begin p:=awalp; q:=awalq; while (q<>nil) or (p<>nil) do begin {if q=nil then x:=p.angka else if p=nil then x:=q.angka else }

x:=p.angka-q.angka; new(baru); baru^.angka:=x; if awalh= nil then

awalh:= baru else akhirh^.berikut:=baru; akhirh:=baru; akhirh^.berikut:=nil; ListBox3.Items.Add(intTostr(x)); p:=p.berikut; q:=q.berikut; end; end;

procedure TForm1.Button4Click(Sender: TObject); begin PtrSementara:=Awalp; while PtrSementara<>nil do With PtrSementara^ do begin if PtrSementara=Awalp then

begin

if angka=0 then Label3.Caption:='' else Label3.Caption:='p(x)= '+floatTostr(angka); end else begin if angka<0 then

Label4.Caption:=Label3.Caption+floatTostr(angka)+'x^'+IntTo str(i) else if angka=0 then Label3.Caption:=Label3.Caption else

Label3.Caption:=Label3.Caption+'+'+floatTostr(angka)+'x^'+In tTostr(i);

end ;

//ListBox1.Items.Add(floatTostr(angka)); PtrSementara:=berikut; i:=i+1; end;

end;

procedure TForm1.Button5Click(Sender: TObject); begin PtrSementara:=Awalq; while PtrSementara<>nil do With PtrSementara^ do

begin if PtrSementara=Awalq then begin

if angka=0 then Label4.Caption:='' else Label4.Caption:='q(x)= '+floatTostr(angka); end else begin if angka<0 then

Label4.Caption:=Label3.Caption+floatTostr(angka)+'x^'+IntTo str(j) else if angka=0 then Label4.Caption:=Label4.Caption else

Label4.Caption:=Label4.Caption+'+'+floatTostr(angka)+'x^'+In tTostr(j);

end ;

//ListBox2.Items.Add(floatTostr(angka)); PtrSementara:=berikut; j:=j+1; end;

end;

procedure TForm1.Button6Click(Sender: TObject); begin i:=0; PtrSementara:=Awalh; while PtrSementara<>nil do With PtrSementara^ do

begin if PtrSementara=Awalh then begin

if angka=0 then Label5.Caption:='' else Label5.Caption:='p(x)+q(x)= '+floatTostr(angka); end else begin if angka<0 then

Label5.Caption:=Label5.Caption+floatTostr(angka)+'x^'+IntTo str(i) else if angka=0 then Label5.Caption:=Label5.Caption else

Label5.Caption:=Label5.Caption+'+'+floatTostr(angka)+'x^'+In tTostr(i);

end ;

//ListBox1.Items.Add(floatTostr(angka)); PtrSementara:=berikut; i:=i+1; end; awalp:=nil; awalq:=nil; awalh:=nil; listbox1.Clear; listbox2.Clear; listbox3.Clear;

end;

end. 2. Form (tampilan) program:

3. Screen shoot

You might also like