Program Interfase; Uses crt; Type win=Record x1,y1,x2,y2:word; text:string[15]; end; sets=set of byte; Const Menu:array[1..5]of win=((x1:1;y1:1;x2:16;y2:1;text:'Invertation'), (x1:1;y1:2;x2:16;y2:2;text:'Summ'), (x1:1;y1:3;x2:16;y2:3;text:'Difference'), (x1:1;y1:4;x2:16;y2:4;text:'Multiplication'), (x1:1;y1:5;x2:16;y2:5;text:'Division')); ns:sets=[1,2]; answers:sets=[1..5]; Var a1,b1,a2,b2,a,b:integer; c1,c2,c:real; st1,st2,st,sa1,sb1,sa2,sb2,sa,sb:string; n,n1,k,i,err,err1,err2:integer; Npos:integer; answer:integer; ch1,ch2:char; Protokol:text; {ЏаЁЈ« 襨Ґ} Procedure Invitation(x1,y1,x2,y2:word;text:string[70]); Begin Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Write(text); End; {Џа®ўҐаЄ ўлЎ®а ¤а®ЎЁ Ё ®вўҐв } Procedure CheckUp(var variable:integer;checkset:sets); Begin While not (variable in checkset) do Begin Invitation(1,7,80,8,'Error! You input incorrect meaning. Write over: '); Readln(variable); End; End; {‚лў®¤ § Є ®ЇҐа жЁЁ} Procedure Operation(x1,y1,x2,y2:word;sign:char); Begin Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Write(sign); End; {ђЁб®ў ЁҐ ЇгЄв ¬Ґо} Procedure DrawWin(w:win;attr:byte); Begin With w do Begin Textattr:=attr; Window(x1,y1,x2,y2); Clrscr; GotoXY(1,1); Write(text); End; End; {ђЁб®ў ЁҐ ¬Ґо б ўл¤Ґ«Ґл¬ ЇгЄв®¬} Procedure DrawMenu(Npos:integer); Begin Clrscr; For i:=1 to 5 do If i=Npos Then DrawWin(menu[i],94) Else DrawWin(menu[i],30); End; {‚ў®¤ ®ЎлЄ®ўҐ®© ¤а®ЎЁ} Procedure InputCommonFraction(var nums,dens:string;var num,den:integer;err1,err2:integer;x1,y1,x2,y2:word); Begin Repeat Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Readln(nums); Val(nums,num,err1); Window(x1,y1+1,x2,y2+1); TextAttr:=15*16; Clrscr; GotoXY(x1,y1+1); Write('____'); Window(x1,y1+2,x2,y2+2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1+2); Readln(dens); Val(dens,den,err2); If (err1<>0) Or (err2<>0) Or ((err1<>0) And (err2<>0)) Or (den=0) Then Invitation(1,7,80,8,'Error! You input incorrect meaning. Write over: '); Until (err1=0) And (err2=0) And (den<>0); End; {‚ў®¤ ¤ҐбпвЁз®© ¤а®ЎЁ} Procedure InputDecimalFraction(var decfr:string;var fr:real;err:integer;x1,y1,x2,y2:word); Begin Repeat Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Readln(decfr); Val(decfr,fr,err); If err<>0 Then Invitation(1,7,80,8,'Error! You input incorrect meaning. Write over: '); Until err=0; End; {‚лў®¤ ®ЎлЄ®ўҐ®© ¤а®ЎЁ} Procedure OutPutCommonFraction(var num,den:integer;x1,y1,x2,y2:word); Begin Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Write(num); Window(x1,y1+1,x2,y2+1); TextAttr:=15*16; Clrscr; GotoXY(x1,y1+1); Write('____'); Window(x1,y1+2,x2,y2+2); TextAttr:=15*16; GotoXY(x1,y1+2); Write(den); End; {‚лў®¤ ¤ҐбпвЁз®© ¤а®ЎЁ} Procedure OutputDecimalFraction(var fr:real;x1,y1,x2,y2:word); Begin Window(x1,y1,x2,y2); TextAttr:=15*16; Clrscr; GotoXY(x1,y1); Write(fr:3:3); End; {‘㬬 ®ЎлЄ®ўҐле ¤а®ЎҐ©} Procedure SummCommonFractions(var num1,den1,num2,den2,num,den:integer); Begin If den1<>den2 Then Begin num:=num1*den2+num2*den1; den:=den1*den2; End Else Begin num:=num1+num2; den:=den1; End; End; {‘㬬 ¤ҐбпвЁзле ¤а®ЎҐ©} Procedure SummDecimalFractions(var fr1,fr2,fr:real); Begin fr:=fr1+fr2; End; {ЏҐаҐў®¤ ¤ҐбпвЁз®© ¤а®ЎЁ ў ®ЎлЄ®ўҐго} Procedure InvertDecFrIntoCommon(var decfr:string;var fr:real;var num,den:integer); Var i,k:integer; power:real; Begin For i:=length(decfr) downto 1 do If decfr[length(decfr)]='0' Then Delete(decfr,length(decfr),1); For i:=length(decfr) downto 1 do If decfr[i]='.' Then k:=i; If frac(fr)=0 Then power:=0 Else power:=length(decfr)-k; den:=trunc(exp(power)*ln(10)); num:=round(fr*den); End; {ЏҐаҐў®¤ ®ЎлЄ®ўҐ®© ¤а®ЎЁ ў ¤ҐбпвЁзго} Procedure InvertComFrIntoDecimal(var num,den:integer;var fr:real); Begin fr:=num/den; End; {ђ §®бвм ®ЎлЄ®ўҐле ¤а®ЎҐ©} Procedure DifferenceCommonFractions(var num1,den1,num2,den2,num,den:integer); Begin If den1<>den2 Then Begin num:=num1*den2-num2*den1; den:=den1*den2; End Else Begin num:=num1-num2; den:=den1; End; End; {ђ §®бвм ¤ҐбпвЁзле ¤а®ЎҐ©} Procedure DifferenceDecimalFractions(var fr1,fr2,fr:real); Begin fr:=fr1-fr2; End; {”¬®¦ҐЁҐ ®ЎлЄ®ўҐле ¤а®ЎҐ©} Procedure MultiplicationCommonFractions(var num1,den1,num2,den2,num,den:integer); Begin num:=num1*num2; den:=den1*den2; End; {”¬®¦ҐЁҐ ¤ҐбпвЁзле ¤а®ЎҐ©} Procedure MultiplicationDecimalFractions(var fr1,fr2,fr:real); Begin fr:=fr1*fr2; End; {„Ґ«ҐЁҐ ®ЎлЄ®ўҐле ¤а®ЎҐ©} Procedure DivisionCommonFractions(var num1,den1,num2,den2,num,den:integer); Begin num:=num1*den2; den:=den1*num2; End; {„Ґ«ҐЁҐ ¤ҐбпвЁзле ¤а®ЎҐ©} Procedure DivisionDecimalFractions(var fr1,fr2,fr:real); Begin fr:=fr1/fr2; End; {‘®Єа 饨Ґ ®ЎлЄ®ўҐ®© ¤а®ЎЁ} Procedure CancellationCommonFraction(var num,den:integer); Var nod,r,n1,n2:integer; Begin n1:=abs(den); n2:=abs(num); While (n1 mod n2)<>0 do Begin r:=n1 mod n2; n1:=n2; n2:=r; End; nod:=n2; num:=trunc(num/nod); den:=trunc(den/nod); End; {Ѓ«®Є ®б®ў®© Їа®Ја ¬¬л} Begin Clrscr; Assign(Protokol,'C:/Temp/Betaversion.txt'); ReWrite(Protokol); Window(1,1,80,30); TextAttr:=7*16; Clrscr; Npos:=1; DrawMenu(Npos); Repeat Ch1:=ReadKey; If ch1=#0 Then ch2:=ReadKey; Case ch1 of #0: Case ch2 of #72: Begin If Npos>1 Then Begin DrawWin(menu[Npos],30); Npos:=Npos-1; DrawWin(menu[Npos],94); End; End; #80: Begin If Npos<5 Then Begin DrawWin(menu[Npos],30); Npos:=Npos+1; DrawWin(menu[Npos],94); End; End; End; #13: Begin Case Npos of 1: Begin Invitation(1,7,80,8,'Input 1 if fraction is common and 2 if fraction is decimal: '); Readln(n); CheckUp(n,ns); Case n of 1: Begin If (a1<>0) and (b1<>0) Then OutputCommonFraction(a1,b1,2,10,6,11) Else InputCommonFraction(sa1,sb1,a1,b1,err1,err2,2,10,6,11); Operation(8,11,10,12,'='); InvertComFrIntoDecimal(a1,b1,c); OutputDecimalFraction(c,2,18,9,19); Writeln(Protokol,a1,'____',b1,'=',c); End; 2: Begin If c1<>0 Then OutputDecimalFraction(c1,2,11,9,12) Else InputDecimalFraction(st1,c1,err,2,11,9,12); Operation(11,11,12,12,'='); InvertDecFrIntoCommon(st1,c1,a,b); CancellationCommonFraction(a,b); OutputCommonFraction(a,b,2,18,6,19); Writeln(Protokol,c1,'=',a,'____',b); End; End; End; 2: Begin Invitation(1,7,80,8,'Input 1 if 1st fraction is common and 2 if 1st fraction is decimal: '); Readln(n); CheckUp(n,ns); Invitation(1,7,80,8,'Input 1 if 2nd fraction is common and 2 if 2nd fraction is decimal: '); Readln(n1); CheckUp(n1,ns); Case n of 1: Begin If (a1<>0) and (b1<>0) Then OutputCommonFraction(a1,b1,2,10,6,11) Else InputCommonFraction(sa1,sb1,a1,b1,err1,err2,2,10,6,11); Operation(7,11,9,12,'+'); Case n1 of 1: InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); 2: Begin InputDecimalFraction(st2,c2,err,10,11,17,12); InvertDecFrIntoCommon(st2,c2,a2,b2); End; End; SummCommonFractions(a1,b1,a2,b2,a,b); CancellationCommonFraction(a,b); OutputCommonFraction(a,b,2,18,6,19); End; 2: Begin If c1<>0 Then OutputDecimalFraction(c1,2,11,9,12) Else InputDecimalFraction(st1,c1,err,2,11,9,12); Operation(7,11,9,12,'+'); Case n1 of 1: Begin InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); InvertComFrIntoDecimal(a2,b2,c2); End; 2: InputDecimalFraction(st2,c2,err,10,11,17,12); End; SummDecimalFractions(c1,c2,c); OutputDecimalFraction(c,2,18,9,19); End; End; End; 3: Begin Invitation(1,7,80,8,'Input 1 if 1st fraction is common and 2 if 1st fraction is decimal: '); Readln(n); CheckUp(n,ns); Invitation(1,7,80,8,'Input 1 if 2nd fraction is common and 2 if 2nd fraction is decimal: '); Readln(n1); CheckUp(n1,ns); Case n of 1: Begin If (a1<>0) and (b1<>0) Then OutputCommonFraction(a1,b1,2,10,6,11) Else InputCommonFraction(sa1,sb1,a1,b1,err1,err2,2,10,6,11); Operation(7,11,9,12,'-'); Case n1 of 1: InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); 2: Begin InputDecimalFraction(st2,c2,err,10,11,17,12); InvertDecFrIntoCommon(st2,c2,a2,b2); End; End; DifferenceCommonFractions(a1,b1,a2,b2,a,b); CancellationCommonFraction(a,b); OutputCommonFraction(a,b,2,18,6,19); End; 2: Begin If c1<>0 Then OutputDecimalFraction(c1,2,11,9,12) Else InputDecimalFraction(st1,c1,err,2,11,9,12); Operation(7,11,9,12,'-'); Case n1 of 1: Begin InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); InvertComFrIntoDecimal(a2,b2,c2); End; 2: InputDecimalFraction(st2,c2,err,10,11,17,12); End; DifferenceDecimalFractions(c1,c2,c); OutputDecimalFraction(c,2,18,9,19); End; End; End; 4: Begin Invitation(1,7,80,8,'Input 1 if 1st fraction is common and 2 if 1st fraction is decimal: '); Readln(n); CheckUp(n,ns); Invitation(1,7,80,8,'Input 1 if 2nd fraction is common and 2 if 2nd fraction is decimal: '); Readln(n1); CheckUp(n1,ns); Case n of 1: Begin If (a1<>0) and (b1<>0) Then OutputCommonFraction(a1,b1,2,10,6,11) Else InputCommonFraction(sa1,sb1,a1,b1,err1,err2,2,10,6,11); Operation(7,11,9,12,'*'); Case n1 of 1: InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); 2: Begin InputDecimalFraction(st2,c2,err,10,11,17,12); InvertDecFrIntoCommon(st2,c2,a2,b2); End; End; MultiplicationCommonFractions(a1,b1,a2,b2,a,b); CancellationCommonFraction(a,b); OutputCommonFraction(a,b,2,18,6,19); End; 2: Begin If c1<>0 Then OutputDecimalFraction(c1,2,11,9,12) Else InputDecimalFraction(st1,c1,err,2,11,9,12); Operation(7,11,9,12,'*'); Case n1 of 1: Begin InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); InvertComFrIntoDecimal(a2,b2,c2); End; 2: InputDecimalFraction(st2,c2,err,10,11,17,12); End; MultiplicationDecimalFractions(c1,c2,c); OutputDecimalFraction(c,2,18,9,19); End; End; End; 5: Begin Invitation(1,7,80,8,'Input 1 if 1st fraction is common and 2 if 1st fraction is decimal: '); Readln(n); CheckUp(n,ns); Invitation(1,7,80,8,'Input 1 if 2nd fraction is common and 2 if 2nd fraction is decimal: '); Readln(n1); CheckUp(n1,ns); Case n of 1: Begin If (a1<>0) and (b1<>0) Then OutputCommonFraction(a1,b1,2,10,6,11) Else InputCommonFraction(sa1,sb1,a1,b1,err1,err2,2,10,6,11); Operation(7,11,9,12,'/'); Case n1 of 1: InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); 2: Begin InputDecimalFraction(st2,c2,err,10,11,17,12); InvertDecFrIntoCommon(st2,c2,a2,b2); End; End; DivisionCommonFractions(a1,b1,a2,b2,a,b); CancellationCommonFraction(a,b); OutputCommonFraction(a,b,2,18,6,19); End; 2: Begin If c1<>0 Then OutputDecimalFraction(c1,2,11,9,12) Else InputDecimalFraction(st1,c1,err,2,11,9,12); Operation(7,11,9,12,'/'); Case n1 of 1: Begin InputCommonFraction(sa2,sb2,a2,b2,err1,err2,10,10,14,11); InvertComFrIntoDecimal(a2,b2,c2); End; 2: InputDecimalFraction(st2,c2,err,10,11,17,12); End; DivisionDecimalFractions(c1,c2,c); OutputDecimalFraction(c,2,18,9,19); End; End; End; End; Invitation(1,22,80,23,'Cancel(1)?/Continue(2)?/Begin at first(3)?/Open Protokol(4)?/Exit(5)? '); Readln(answer); CheckUp(answer,answers); If answer=1 Then Begin If (a<>0) And (b<>0) Then Begin a:=a1; b:=b1; End; If c<>0 Then Begin c:=c1; str(c,st); End; Window(1,7,80,25); TextAttr:=7*16; Clrscr; End; If answer=2 Then Begin If (a<>0) and (b<>0) Then Begin a1:=a; b1:=b; End; If c<>0 Then Begin c1:=c; str(c1,st1); End; Window(1,7,80,25); Textattr:=7*16; Clrscr; End; If answer=3 Then Begin Window(1,7,80,25); Textattr:=7*16; Clrscr; a1:=0; b1:=0; c1:=0; End; If answer=4 Then While not EOF(Protokol) do Begin Readln(Protokol,a1,b1,c1,a,b,c); Writeln(a1,b1,c1,a,b,c); End; End; End; Until answer=5; Close(Protokol); End.