يه ماشين حساب ساده در پاسكال
{------------------------------- program one -------------------------------
---------------------------------------------------------------------------}
uses crt,dos;
var
num1,num2,num:real;
st2,st1,amal,str1,str2,strkol:string;
key:char;
sum:string;
i,j:integer;
{******************FUNCTION FACT ************}
function FACT(m:real):real;
begin
IF m>1 then
fact:=m*fact(m-1)
else
fact:=1;
end;
{*********************** TAWAN ***********************}
function tawan(xx:real;yy:integer):real;
var ti:integer;
mm:real;
begin
mm:=1;
if yy>=0 then
begin
for ti:=1 to yy do
mm:=mm*xx;
end;
if yy<0 then
begin
for ti:=1 to -yy do
mm:=mm*xx;
end;
if yy>=0 then tawan:=mm;
if yy<0 then tawan:=1/mm;
end;
{*********************** ST ***********************}
function st(x:real):string;
var s:string;
begin
str (x:15:5,s);
st:=s;
end;
{*********************** VA ***********************}
function va(s:string):real;
var r:real;
int1:integer;
begin
val (s,r,int1);
va:=r;
end;
{*********************** Main ***********************}
begin
clrscr;
sum:='';
textcolor (7);
textbackground (0);
gotoxy (10,04);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
gotoxy (10,05);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
gotoxy (10,06);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
gotoxy (10,07);write (' 1 2 3 + ^ Sin = s ASin = S ');
gotoxy (10,08);write (' 4 5 6 - % Cos = c ACos = C ');
gotoxy (10,09);write (' 7 8 9 * B Tan = t ATan = T ');
gotoxy (10,10);write (' C 0 . / e Cot = o ACot = O ');
repeat
key:=readkey;
sum:=sum+key;
if pos(key,'%^+-*/')<>0 then
begin
amal:=key;
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
end;
if pos(key,'0123456789.')<>0 then
begin
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
if pos(key,'0123456789.')=0 then
begin
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
delete (sum,length(sum),1);
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
case key of
#8:begin
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
delete (sum,length(sum),1);
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
#9:begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:='';
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
's':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(sin((va(sum)*pi)/180));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'c':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(cos((va(sum)*pi)/180));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
't':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st((sin((va(sum)*pi)/180))/(cos((va(sum)*pi)/180)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'o':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st((cos((va(sum)*pi)/180))/(sin((va(sum)*pi)/180)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'S':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(1/(sin((va(sum)*pi)/180)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'C':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(1/(cos((va(sum)*pi)/180)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'T':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(1/((sin((va(sum)*pi)/180))/(cos((va(sum)*pi)/180))));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'O':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(1/((cos((va(sum)*pi)/180))/(sin((va(sum)*pi)/180))));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'e':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(exp(va(sum)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'f':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
sum:=st(fact(va(sum)));
while sum[1]=' ' do
delete (sum,1,1);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'+':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st(va(sum)+num2);
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'-':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st(va(sum)-num2);
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'*':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st(va(sum)*num2);
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'/':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st(va(sum)/num2);
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'^':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st(tawan(va(sum),trunc(num2)));
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
'%':begin
textcolor (7);
gotoxy (10,5);write ('غغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغغ');
textcolor (0);textbackground (7);
gotoxy (10,5);readln (num2);
sum:=st((va(sum)*num2)/100);
while sum[1]=' ' do
delete (sum,1,1);
amal:='=';
textcolor (0);textbackground (7);
gotoxy (8,5);write (amal);
textcolor (0);textbackground (7);
gotoxy (10,5);write (sum);
end;
end;
until key=#27;
end.