Postingan

Menampilkan postingan dari Maret, 2011

Program merubah notasi infix menjadi postfix

uses crt; const max_elemen = 255; type s255 = string [max_elemen]; tumpukan = record rinci : s255; atas : 0..max_elemen end; var infix : s255; lagi : char; function valensi (tanda_op : char) : integer; begin case tanda_op of '^' : valensi := 3; '*', '/' : valensi := 2; '+', '-' : valensi := 1; '(' : valensi := 0 end end; procedure push (var t : tumpukan; elemen : char); begin t.atas := t.atas +1; t.rinci[t.atas] := elemen end; function pop (var t : tumpukan) : char; begin pop := t.rinci[t.atas]; t.atas := t.atas - 1 end; procedure konversi_cetak (infix : s255); var i : integer; operator : set of char; temp, kar : char; t : tumpukan; test : boolean; begin operator := ['^']+['*']+['/']+['+']+['-']; for i := 1 to length (infix) do begin kar := infix[i]; if kar = '(' then push (t, kar) else if kar = ')' then begin while t.rinci[t.atas] <> '(' do write (pop(t) : 2); temp :=

TUGAS SOD 2(membuat operasi string dalam pascal)

uses crt; var x: integer; z:integer; jawab:char; h,i,j,k:string; begin repeat clrscr; writeln('menu operator string'); writeln('1.menggabungkan string:'); writeln('2.menghitung panjang string:'); writeln('3.menyisipkan string:'); writeln('<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>'); writeln('masukkan pilihan anda:'); readln(x); case x of 1:begin write('kata1:');readln(h); write('kata2:');readln(i); write('kata3:');readln(j); k:=concat(h,i,j); writeln(k); end; 2:begin write('kata1:');readln(h); write('kata2:');readln(i); write('kata3:');readln(j); k:=concat(h,i,j); z:=length(k); writeln('panjang string :',z);readln; end; 3:begin write('kata1:');readln(h); write('kata2:');readln(i); write('kata3:');readln(j); k:=concat(h,i,j); insert('&',k,10); writeln(k);r