nayay17 0 Newbie Poster

Dear All,
Could you tell me how to complete this coding? so it can run like the program that I have attached.

Cheers,

type
  node = ^data;
  data  = record
     nama  : string;
     ipk : real; {tipe data info}
     yudisium:string;
     next : node;
  end;
        linkedlist = record
        first : node
  end;
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button1: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    StringGrid1: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ListTraversal(L:linkedlist);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
   
   
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  baru : node;
  L:linkedlist;
  nama:string;
  ipk:real;
  yudisium:string;
implementation

{$R *.dfm}

function createlist:node;
var p:node;
begin
  New(P);
  P^.nama  := nama;
  P^.ipk := ipk;
  P^.yudisium:=yudisium;
  if P^.ipk>=3.5 then P^.yudisium:='Cum Laude'
  else if P^.ipk>=3.0 then P^.yudisium:='Sangat Memuaskan'
  else if P^.ipk>=2.0 then P^.yudisium:='Memuaskan'
  else if P^.ipk<=1.9 then P^.yudisium:='Menyedihkan';
  P^.next := nil;
  createlist:=P;
end;

procedure InsertFirst(var L:linkedlist;p:node);
begin
	P^.next := L.first;
	L.first := P;
end;

procedure TForm1.ListTraversal(L:linkedlist);
var p:node;
    i:integer;
begin
  P:=L.first;
  i:=1;
  StringGrid1.Cells[0,0]:='NAMA';
  StringGrid1.Cells[1,0]:='IPK';
  StringGrid1.Cells[2,0]:='YUDISIUM';
  while (P<>nil) do
    begin
    StringGrid1.RowCount:=i+1;
    StringGrid1.Cells[0,i]:=P^.nama;
    StringGrid1.Cells[1,i]:=FloatToStr(P^.ipk);
    StringGrid1.Cells[2,i]:=P^.yudisium;
    P := P^.next;
    i:=i+1;
    end;
end;


procedure InsertBefore(var L:linkedlist;baru:node;x:integer);
var  P,precP : node;
     Found : boolean;
     i:integer;
begin
  Found := false;
  PrecP :=nil;
  P :=L.first;
  while(p<>nil) and (not found) do
    begin
      if RowCount=x then
         begin
         baru^.next:=P;
         PrecP.next:=baru;
         Found :=true;
         end
      else
         begin
         PrecP := P;
         P := P^.next;
         end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  nama:=Edit1.Text;
  ipk:=StrToFloat(Edit2.Text);
  baru:=createlist;
  InsertFirst(L,baru);
end;



procedure DeleteFirst(var L:linkedlist);
var P: node;
begin
	if (L.first <> nil) then
	   begin
     P:=L.first;
     L.first := L.first^.next;
     Dispose(p);
     end;
end;

procedure DeleteLast(var L:linkedlist);
var Last, precLast,P: node;
begin
	if (L.first <> nil) then
	  begin
      Last :=L.first;
      PrecLast :=nil;
      while (Last^.next<>nil) do
        begin
        PrecLast :=Last;
        Last :=Last^.next;
        end;
      P:=last;
      if (precLast=nil) then
         L.first:=nil
      else precLast^.next :=nil;
         Dispose(p);
	  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   ListTraversal(L);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
    i:integer;
    s:string;
begin
  s:=InputBox('Insert Anywhere','Insert at','');
  i:=StrToInt(s);
  nama:=Edit1.Text;
  ipk:=StrToFloat(Edit2.Text);
  baru:=createlist;
  InsertBefore(L,baru,i);
end;
end.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.