Iniciar sesiónCrear cuenta

# Pascal/Turbo Pascal - Calculadora!

Vista:

Publicado por Nayelii (2 intervenciones) el 20/04/2012 06:18:04
Hello! me podrian ayudar con un programa que sea una calculadora en pascal?? pleees!!
Valora esta pregunta
0

Publicado por ramon (2100 intervenciones) el 26/04/2012 17:48:58
{Vamos a ver esto te sirve}

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;

procedure mascara;
begin
gotoxy(4,1);write('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
gotoxy(4,2);write('³ ³');
gotoxy(4,3);write('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ');
gotoxy(4,4);write('ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿');
gotoxy(4,5);write('³ ³ ³ ³ ³ ³');
gotoxy(4,6);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
gotoxy(4,7);write('³ ³ ³ ³ ³ ³');
gotoxy(4,8);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
gotoxy(4,9);write('³ ³ ³ ³ ³ ³');
gotoxy(4,10);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
gotoxy(4,11);write('³ ³ ³ ³ ³ ³');
gotoxy(4,12);write('ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ');
gotoxy(6,5);write('7');
gotoxy(6,7);write('4');
gotoxy(6,9);write('1');
gotoxy(6,11);write('0');
gotoxy(10,5);write('8');
gotoxy(10,7);write('5');
gotoxy(10,9);write('2');
gotoxy(10,11);write('.');
gotoxy(14,5);write('9');
gotoxy(14,7);write('6');
gotoxy(14,9);write('3');
gotoxy(14,11);write('=');
gotoxy(18,5);write('%');
gotoxy(18,7);write('X');
gotoxy(18,9);write('-');
gotoxy(18,11);write('+');
gotoxy(21,5);write('Rsv');
gotoxy(21,7);write('Rsv');
gotoxy(21,9);write('Rsv');
gotoxy(21,11);write('Sqr');
gotoxy(4,14);write('Teclas a Usar del Teclado Activar [BLOQ NUM] [ESC Fin]');
gotoxy(4,15);write('[Teclado Numerico], [= Enter], [Sqr AvPag],[% RePag]');
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;

var
resl : real;
v : string;
begin
resl := sqrt(nn);
str(resl:8:2,v);
end;

begin
clrscr;
mascara;
sa := 1;
valor := ' ';
valor[0] := chr(0);
dato11 := 0.00;
dato22 := 0.00;
sal := false;
cursoroff;
repeat
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;
end;
end;
repeat
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.
Valora esta respuesta
0