Bagi teman-teman yang ingin belajar membuat kalkulator sederhana dengan pascal, silakan ini ada acuannya.
program
asti_procedure_function_kalkulator;
uses wincrt;
var
menu:1..13;
x,y,z:real;
o,p:integer;
neg:real;
jawab:string;
procedure
pilihan;
begin
writeln('^^^^^^^^^^^^^^^^^^^^^^^^');
writeln(' .::KALKULATOR::. ');
writeln('^^^^^^^^^^^^^^^^^^^^^^^^');
writeln('1. Penjumlahan (+)');
writeln('2. Pengurangan (-)');
writeln('3. Perkalian (.)');
writeln('4. Pembagian (:)');
writeln('5. Kuadrat (a^x)');
writeln('6. Akar Kuadrat');
writeln('7. Fungsi (a+b)^2');
writeln('8. Fungsi (a-b)^2');
writeln('9. Eksponensial (e^x)');
writeln('10. Ln (lnx)');
writeln('11. Faktorial (n!)');
writeln('12. Integer (Int)');
writeln('13. Keluar program');
writeln;
write('Operasi yang akan Anda gunakan=
');readln(menu);
end;
procedure
penjumlahan;
begin
writeln('-==PENJUMLAHAN==-');
writeln(' a+b
');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
z:=x+y;
writeln(x:4:2,' + ',y:4:2,' = ',z:4:2);
end;
procedure
pengurangan;
begin
writeln('-==PENGURANGAN==-');
writeln(' a-b
');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
z:=x-y;
writeln(x:4:2,' - ',y:4:2,' = ',z:4:2);
end;
procedure
perkalian;
begin
writeln('-==PERKALIAN==-');
writeln(' a.b
');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
z:=x*y;
writeln(x:4:2,' . ',y:4:2,' = ',z:4:2);
end;
procedure
pembagian;
begin
writeln('-==PEMBAGIAN==-');
writeln(' a:b
');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
if y=0 then
writeln('hasil pembagian dengan 0= tak
hingga')
else
begin
z:=x/y;
writeln(x:4:2,' : ',y:4:2,' = ',z:4:2);
end;
end;
function
kuadrat(a,b:integer):longint;
var i:byte;
pk:longint;
begin
pk:=1;
if b=0 then pk:=1
else
for i:=1 to b do
pk:=pk*a;
kuadrat:=pk;
end;
procedure
akar_kuadrat;
begin
writeln('-==AKAR KUADRAT==-');
writeln(' /-----
');
writeln(' \/
x ');
write('Masukkan nilai x= ');readln(x);
if x<0 then
writeln('hasil akar kuadrat bilangan
negatif adalah bilangan imajiner')
else
begin
z:=sqrt(x);
writeln('akar ',x:4:2,' = ',z:4:2);
end;
end;
procedure
fungsi1;
begin
writeln('-==FUNGSI (a+b)^2==-');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
z:=sqr(x)+(2*x*y)+sqr(y);
writeln('Fungsi (',x:4:2,'+',y:4:2,')^2 =
',z:4:2);
end;
procedure
fungsi2;
begin
writeln('-==FUNGSI (a-b)^2==-');
write('Masukkan nilai a= ');readln(x);
write('Masukkan nilai b= ');readln(y);
z:=sqr(x)-(2*x*y)+sqr(y);
writeln('Fungsi (',x:4:2,'-',y:4:2,')^2 =
',z:4:2);
end;
procedure
eksponensial;
begin
writeln('-==EKSPONENSIAL==-');
writeln(' e^x ');
write('Masukkan nilai x= ');readln(x);
z:=exp(x);
writeln('e pangkat ',x:2:2,' = ',z:2:2);
end;
procedure
lnx;
begin
writeln('-==LN==-');
writeln('
lnx ');
write('Masukkan nilai x= ');readln(x);
if (x<1) then writeln('Nilai yang Anda
masukkan salah!')
else
begin
z:=ln(x);
writeln('ln',x:4:2,' = ',z:4:2);
end;
end;
function
faktorial(x:integer):longint;
begin
if (x=0) or
(x=1) then faktorial:=1
else
faktorial:=x*faktorial(x-1);
end;
procedure
inte;
begin
writeln('-==INTEGER==-');
writeln(' int ');
write('Masukkan
nilai desimal= ');readln(x);
z:=Int(x);
writeln('int
',x:2:6,' = ',z:2:2);
end;
begin
repeat
begin
clrscr;
pilihan;
clrscr;
case menu of
1: penjumlahan;
2: pengurangan;
3: perkalian;
4: pembagian;
5: begin
writeln('-==KUADRAT==-');
writeln(' a^x
');
write('Masukkan nilai a= ');readln(o);
write('Masukkan nilai x= ');readln(p);
if p<0 then
begin
neg:=1/(kuadrat(o,abs(p)));
writeln(o,' pangkat ',p,' =
',neg:4:6);
end
else
writeln(o,' pangkat ',p,' =
',kuadrat(o,p));
end;
6: akar_kuadrat;
7: fungsi1;
8: fungsi2;
9: eksponensial;
10: lnx;
11: begin
writeln('-==FAKTORIAL==-');
writeln(' n!
');
write('Masukkan nilai n=
');readln(o);
if (o<0) then
begin
writeln('Nilai yang Anda
masukkan salah!');
writeln('Nilai n harus positif');
end
else
writeln(o,'! = ',faktorial(o));
end;
12: inte;
13: donewincrt;
end;
writeln;
writeln;
write('Apakah
Anda ingin mencoba lagi? <y/t> ');readln(jawab);
end;
until
(jawab<>'y');
end.Selamat mencoba .....Semangat Belajar !!!
0 komentar :
Posting Komentar