Program calc;
uses crt,mouse,sysutils;
var r,sim:char;
g:byte;
a,b,res:real;
procedure init_mouse;
var i:byte;
begin (*inizializza il mouse*)
initmouse;
i:=detectmouse;
if i=0 then
begin
donemouse;
writeln('ERRORE')
end
else
setmousexy(0,0)
end;
procedure write_calc;
begin (*output della calcolatrice*)
gotoxy(2,1);
write('CALCOLATRICE');
gotoxy(1,5);
writeln('ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿');
writeln('³AC ³³ESC³³ ö ³³ x ³');
writeln('ÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙ');
writeln('ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿');
writeln('³ 7 ³³ 8 ³³ 9 ³³ - ³');
writeln('ÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙ');
writeln('ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿');
writeln('³ 4 ³³ 5 ³³ 6 ³³ + ³');
writeln('ÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙ');
writeln('ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿ÚÄÄÄ¿');
writeln('³ 1 ³³ 2 ³³ 3 ³³ ³');
writeln('ÀÄÄÄÙÀÄÄÄÙÀÄÄÄÙ³ ³');
writeln('ÚÄÄÄÄÄÄÄÄ¿ÚÄÄÄ¿³ ³');
writeln('³ 0 ³³ . ³³ = ³');
writeln('ÀÄÄÄÄÄÄÄÄÙÀÄÄÄÙÀÄÄÄÙ')
end;
function readall:char;
var x,y:byte;
eventi:tmouseevent;
begin (*input del mouse*)
readall:='?';
repeat
getmouseevent(eventi);
for x:=1 to 10 do
for y:=17 to 19 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='0'
end;
for x:=1 to 5 do
for y:=14 to 16 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='1'
end;
for x:=6 to 10 do
for y:=14 to 16 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='2'
end;
for x:=11 to 15 do
for y:=14 to 16 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='3'
end;
for x:=1 to 5 do
for y:=11 to 13 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='4'
end;
for x:=6 to 10 do
for y:=11 to 13 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='5'
end;
for x:=11 to 15 do
for y:=11 to 13 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='6'
end;
for x:=1 to 5 do
for y:=8 to 10 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='7'
end;
for x:=6 to 10 do
for y:=8 to 10 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='8'
end;
for x:=11 to 15 do
for y:=8 to 10 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='9'
end;
for x:=11 to 15 do
for y:=17 to 19 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='.'
end;
for x:=16 to 20 do
for y:=11 to 13 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='+'
end;
for x:=16 to 20 do
for y:=8 to 10 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='-'
end;
for x:=16 to 20 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='*'
end;
for x:=11 to 15 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='/'
end;
for x:=16 to 20 do
for y:=14 to 19 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='='
end;
for x:=1 to 5 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='a'
end;
for x:=6 to 10 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
readall:='e'
end
until readall<>'?';
case readall of
'0': g:=1;
'1': g:=1;
'2': g:=1;
'3': g:=1;
'4': g:=1;
'5': g:=1;
'6': g:=1;
'7': g:=1;
'8': g:=1;
'9': g:=1;
'.': g:=2;
'+': g:=3;
'-': g:=3;
'*': g:=3;
'/': g:=3;
'=': g:=4;
'a': g:=5;
'e': g:=6
end
end;
function trovanum:real;
var i,l:byte;
n:array[1..18] of char;
nstr:string;
begin (*output dei numeri*)
for i:=1 to 18 do
n[i]:=' ';
gotoxy(2,3);
clreol;
while r='0' do
begin
n[1]:=r;
write(n[1]);
gotoxy(2,3);
r:=readall
end;
i:=0;
repeat
i:=i+1;
case g of
1:begin
n[i]:=r;
write(n[i])
end;
2:begin
if i=1 then
begin
n[i]:='0';
write(n[i]);
i:=i+1;
n[i]:=r;
write(n[i])
end
else
begin
n[i]:=r;
write(n[i])
end;
l:=0;
repeat
l:=l+1;
repeat
r:=readall
until g<>2;
case g of
1:begin
n[i+l]:=r;
write(n[i+l])
end;
3:begin
sim:=r;
break
end;
4..5:break;
6:halt
end
until (i+l)=18;
break
end;
3:begin
sim:=r;
break
end;
4..5:break;
6:halt
end;
r:=readall
until i=18;
if n[i+l]='.' then
n[i+l]:=' ';
nstr:=concat(n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14],n[15],n[16],n[17],n[18]);
trovanum:=strtofloat(nstr)
end;
function trovares:real;
var rstr:string;
begin (*output del risultato*)
case sim of
'+':trovares:=a+b;
'-':trovares:=a-b;
'*':trovares:=a*b;
'/':trovares:=a/b
end;
gotoxy(2,3);
clreol;
rstr:=floattostr(trovares);
write(rstr)
end;
procedure tutto;
begin (*tutto*)
if (g=1) or (g=2) or (g=4) then
begin
repeat
r:=readall;
if g=3 then
sim:=r
until (g=3) or (g=5) or (g=6)
end;
repeat
if (g<>5) and (g<>6) then
begin
repeat
r:=readall;
if g=3 then
sim:=r
until (g=1) or (g=2) or (g=5) or (g=6)
end;
case g of
1..2:begin
b:=trovanum;
if b=0 then
begin
gotoxy(2,3);
clreol;
write('IMPOSSIBILE');
repeat
r:=readall
until (g=1) or (g=2) or (g=5) or (g=6);
break
end;
case g of
1..2:begin
repeat
r:=readall
until (g=3) or (g=4) or (g=5) or (g=6);
case g of
3:begin
res:=trovares;
sim:=r;
a:=res
end;
4:begin
res:=trovares;
repeat
r:=readall;
case g of
3:begin
a:=res;
sim:=r
end;
4:begin
a:=res;
res:=trovares
end;
6:halt
end
until (g=1) or (g=2) or (g=3) or (g=5);
if g<>3 then
break
end;
5:break;
6:halt
end
end;
3:begin
res:=trovares;
sim:=r;
a:=res
end;
4:begin
res:=trovares;
repeat
r:=readall;
case g of
3:begin
sim:=r;
a:=res
end;
4:begin
a:=res;
res:=trovares
end;
6:halt
end
until (g=1) or (g=2) or (g=3) or (g=5);
if g<>3 then
break
end;
5:break;
6:halt
end
end;
5:break;
6:halt
end
until keypressed
end;
begin (*programma*)
clrscr;
cursoroff;
init_mouse;
decimalseparator:='.';
write_calc;
gotoxy(2,3);
write('0');
r:=readall;
repeat
case g of
1..2:begin
a:=trovanum;
tutto
end;
3:begin
sim:=r;
a:=0;
tutto
end;
4:r:=readall;
5:begin
gotoxy(2,3);
clreol;
write('0');
r:=readall;
end;
6:halt
end
until keypressed;
donemouse
end.