program calculs;
uses
crt, dos;
var
total, valores1, valores2 : real;
menori : real;
regs : registers;
raton : boolean;
tec, tecla : char;
x, y : word;
sa : integer;
vali, valor : string[14];
sal : boolean;
dato11, dato22 : real;
signo : char;
procedure cursorOn;assembler;
asm
mov ah,3
mov bh,0
int $10
and ch,not $20
mov ah,1
int $10
end;
procedure cursorOff;assembler;
asm
mov ah,3
mov bh,0
int $10
or ch,$20
mov ah,1
int $10
end;
function intstring(n : integer) : string;
var
dh : string;
begin
str(n,dh);
intstring := dh;
end;
function stringreal(s : string) : real;
var
r : real;
er : integer;
begin
val(s,r,er);
stringreal := r;
end;
function realstring(r : real) : string;
var
dac1, dac : string[15];
i : integer;
salida : boolean;
begin
str(r:12:3,dac);
i := 1;
salida := false;
repeat
if dac[i] <> '.' then
begin
dac1[0] := chr(i);
dac1[i] := dac[i];
inc(i);
end
else
begin
if (dac[i + 1] <> '0') or (dac[i + 2] <> '0') then
begin
realstring := dac;
salida := true;
end
else
begin
realstring := dac1;
salida := true;
end;
end;
until salida = true;
end;
function suma(nn, nn1 : real) : string;
var
resl : real;
v : string;
begin
resl := nn + nn1;
str(resl:8:2,v);
suma := v;
end;
function resta(nn, nn1 : real) : string;
var
resl : real;
v : string;
begin
resl := nn + nn1;
str(resl:8:2,v);
resta := v;
end;
function multiplica(nn, nn1 : real) : string;
var
resl : real;
v : string;
begin
resl := nn * nn1;
str(resl:8:2,v);
multiplica := v;
end;
function dividir(nn, nn1 : real) : string;
var
resl : real;
v : string;
begin
resl := nn / nn1;
str(resl:8:2,v);
dividir := v;
end;
function tantopor100(nn, nn1 : real) : string;
var
resl : real;
v : string;
begin
resl := nn * nn1 / 100;
str(resl:8:2,v);
tantopor100 := v;
end;
function raizcuadrada(nn : real) : string;
var
resl : real;
v : string;
begin
resl := sqrt(nn);
str(resl:8:2,v);
raizcuadrada := v;
end;
begin
clrscr;
mascara;
sa := 1;
valor := ' ';
valor[0] := chr(0);
dato11 := 0.00;
dato22 := 0.00;
sal := false;
cursoroff;
repeat
tec := readkey;
if tec in [#46,#48..#57] then
begin
valor[0] := chr(sa);
valor[sa] := tec;
inc(sa);
gotoxy(22 - sa,2);write(valor);
end;
if tec in [#8] then
begin
if sa = 1 then
begin
end
else
begin
dec(sa);
valor[0] := chr(sa);
valor[sa] := ' ';
gotoxy(22 - sa,2);write(valor);
end;
end;
if tec = #73 then
begin
signo := '%';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
vali[0] := #15;
vali := realstring(dato11);
valor := ' ';
valor[0] := chr(0);
sa := 1;
gotoxy(9,2);write(' ');
end;
if tec = #42 then
begin
signo := '*';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
vali[0] := #15;
vali := realstring(dato11);
valor := ' ';
valor[0] := chr(0);
sa := 1;
gotoxy(9,2);write(' ');
end;
if tec = #47 then
begin
signo := '/';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
vali[0] := #15;
vali := realstring(dato11);
valor := ' ';
valor[0] := chr(0);
sa := 1;
gotoxy(9,2);write(' ');
end;
if tec = #45 then
begin
signo := '-';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
vali[0] := #15;
vali := realstring(dato11);
valor := ' ';
valor[0] := chr(0);
sa := 1;
gotoxy(9,2);write(' ');
end;
if tec = #13 then
begin
sal := true;
end;
if tec = #43 then
begin
signo := '+';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
vali[0] := #15;
vali := realstring(dato11);
valor := ' ';
valor[0] := chr(0);
sa := 1;
gotoxy(9,2);write(' ');
end;
if tec = #81 then
begin
signo := '@';
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end;
sal := true;
gotoxy(9,2);write(' ');
end;
if sal = true then
begin
gotoxy(9,2);write(' ');
case signo of
'+' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
gotoxy(12,2);write(suma(dato11,dato22));
end;
'-' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
gotoxy(12,2);write(resta(dato11,dato22));
end;
'*' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
if dato22 = 0.00 then
begin
dato22 := dato11;
end;
gotoxy(12,2);write(multiplica(dato11,dato22));
end;
'/' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
if dato22 = 0.00 then
begin
dato22 := dato11;
end;
gotoxy(12,2);write(dividir(dato11,dato22));
end;
'%' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end
else
begin
dato22 := stringreal(valor);
end;
if dato22 = 0.00 then
begin
dato22 := dato11;
end;
gotoxy(12,2);write(tantopor100(dato11,dato22));
end;
'@' : begin
if dato11 = 0.00 then
begin
dato11 := stringreal(valor);
end;
gotoxy(12,2);write(raizcuadrada(dato11));
end;
end;
gotoxy(2,23);write('Pulse [BARRA ESPACIADORA]');
repeat
tecla := readkey;
if tecla = #32 then
begin
sa := 1;
valor := ' ';
valor[0] := chr(0);
dato11 := 0.00;
dato22 := 0.00;
sal := false;
gotoxy(9,2);write(' ');
gotoxy(2,23);write(' ');
end;
until tecla = #32;
end;
until tec = #27;
cursoron;
end.