Здравствуйте! У меня тут возникла такая проблема: нужно реализовать калькулятор, оперирующий с обыкновенными и десятичными дробями, и протокол его работы записать в файл, причем если произошла ошибка, то об этом тоже написать в протоколе. Саму программу калькулятора я сделала, а вот как записать протокол не знаю. И еще: когда я обыкновенную дробь перевожу в десятичную, а потом наоборот, прога вылетает с ошибкой 201. Помогите, плиз!
volvo
16.05.2006 20:03
Ну, если сделала программу, то ХОТЯ БЫ присоедини ее!!! Что же ты хочешь, чтобы и мы заново ее делали, чтоб потом тебе показать, как ведется Log ?
Насчет ошибки №201 - у тебя в программе ошибка в 17-ой строке! Телепаты в отпуске. Нужна помощь - показывай программу.
Elien
16.05.2006 20:03
Упс, кажется, файл не крепится...
Вот код(Показать/Скрыть)
Program Interfase;
Uses crt;
Type win=Record
x1,y1,x2,y2:word;
text:string[15];
end;
sets=setof 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;
{Џа(r)ўҐаЄ ўлЎ(r)а ¤а(r)ЎЁ Ё (r)⢥в }Procedure CheckUp(var variable:integer;checkset:sets);
BeginWhilenot (variable in checkset) doBegin
Invitation(1,7,80,8,'Error! You input incorrect meaning. Write over: ');
Readln(variable);
End;
End;
{‚лў(r)¤ § Є (r)ЇҐа жЁЁ}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;
{ђЁб(r)ў ЁҐ ЇгЄв ¬Ґо}Procedure DrawWin(w:win;attr:byte);
BeginWith w doBegin
Textattr:=attr;
Window(x1,y1,x2,y2);
Clrscr;
GotoXY(1,1);
Write(text);
End;
End;
{ђЁб(r)ў ЁҐ ¬Ґо б ўл¤Ґ«Ґл¬ ЇгЄв(r)¬}Procedure DrawMenu(Npos:integer);
Begin
Clrscr;
For i:=1to5doIf i=Npos Then DrawWin(menu[i],94)
Else DrawWin(menu[i],30);
End;
{‚ў(r)¤ (r)ЎлЄ(r)ўҐ(r)(c) ¤а(r)ЎЁ}Procedure InputCommonFraction(var nums,dens:string;var num,den:integer;err1,err2:integer;x1,y1,x2,y2:word);
BeginRepeat
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;
{‚ў(r)¤ ¤ҐбпвЁз(r)(c) ¤а(r)ЎЁ}Procedure InputDecimalFraction(var decfr:string;var fr:real;err:integer;x1,y1,x2,y2:word);
BeginRepeat
Window(x1,y1,x2,y2);
TextAttr:=15*16;
Clrscr;
GotoXY(x1,y1);
Readln(decfr);
Val(decfr,fr,err);
If err<>0Then Invitation(1,7,80,8,'Error! You input incorrect meaning. Write over: ');
Until err=0;
End;
{‚лў(r)¤ (r)ЎлЄ(r)ўҐ(r)(c) ¤а(r)ЎЁ}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;
{‚лў(r)¤ ¤ҐбпвЁз(r)(c) ¤а(r)ЎЁ}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;
{‘㬬 (r)ЎлЄ(r)ўҐле ¤а(r)ЎҐ(c)}Procedure SummCommonFractions(var num1,den1,num2,den2,num,den:integer);
BeginIf den1<>den2 ThenBegin
num:=num1*den2+num2*den1;
den:=den1*den2;
EndElseBegin
num:=num1+num2;
den:=den1;
End;
End;
{‘㬬 ¤ҐбпвЁзле ¤а(r)ЎҐ(c)}Procedure SummDecimalFractions(var fr1,fr2,fr:real);
Begin
fr:=fr1+fr2;
End;
{ЏҐаҐў(r)¤ ¤ҐбпвЁз(r)(c) ¤а(r)ЎЁ ў (r)ЎлЄ(r)ўҐго}Procedure InvertDecFrIntoCommon(var decfr:string;var fr:real;var num,den:integer);
Var i,k:integer;
power:real;
BeginFor i:=length(decfr) downto1doIf decfr[length(decfr)]='0'Then
Delete(decfr,length(decfr),1);
For i:=length(decfr) downto1doIf decfr[i]='.'Then k:=i;
If frac(fr)=0Then power:=0Else power:=length(decfr)-k;
den:=trunc(exp(power)*ln(10));
num:=round(fr*den);
End;
{ЏҐаҐў(r)¤ (r)ЎлЄ(r)ўҐ(r)(c) ¤а(r)ЎЁ ў ¤ҐбпвЁзго}Procedure InvertComFrIntoDecimal(var num,den:integer;var fr:real);
Begin
fr:=num/den;
End;
{ђ §(r)бвм (r)ЎлЄ(r)ўҐле ¤а(r)ЎҐ(c)}Procedure DifferenceCommonFractions(var num1,den1,num2,den2,num,den:integer);
BeginIf den1<>den2 ThenBegin
num:=num1*den2-num2*den1;
den:=den1*den2;
EndElseBegin
num:=num1-num2;
den:=den1;
End;
End;
{ђ §(r)бвм ¤ҐбпвЁзле ¤а(r)ЎҐ(c)}Procedure DifferenceDecimalFractions(var fr1,fr2,fr:real);
Begin
fr:=fr1-fr2;
End;
{”¬(r)¦ҐЁҐ (r)ЎлЄ(r)ўҐле ¤а(r)ЎҐ(c)}Procedure MultiplicationCommonFractions(var num1,den1,num2,den2,num,den:integer);
Begin
num:=num1*num2;
den:=den1*den2;
End;
{”¬(r)¦ҐЁҐ ¤ҐбпвЁзле ¤а(r)ЎҐ(c)}Procedure MultiplicationDecimalFractions(var fr1,fr2,fr:real);
Begin
fr:=fr1*fr2;
End;
{„Ґ«ҐЁҐ (r)ЎлЄ(r)ўҐле ¤а(r)ЎҐ(c)}Procedure DivisionCommonFractions(var num1,den1,num2,den2,num,den:integer);
Begin
num:=num1*den2;
den:=den1*num2;
End;
{„Ґ«ҐЁҐ ¤ҐбпвЁзле ¤а(r)ЎҐ(c)}Procedure DivisionDecimalFractions(var fr1,fr2,fr:real);
Begin
fr:=fr1/fr2;
End;
{‘(r)Єа 饨Ґ (r)ЎлЄ(r)ўҐ(r)(c) ¤а(r)ЎЁ}Procedure CancellationCommonFraction(var num,den:integer);
Var nod,r,n1,n2:integer;
Begin
n1:=abs(den);
n2:=abs(num);
While (n1 mod n2)<>0doBegin
r:=n1 mod n2;
n1:=n2;
n2:=r;
End;
nod:=n2;
num:=trunc(num/nod);
den:=trunc(den/nod);
End;
{Ѓ«(r)Є (r)б(r)ў(r)(c) Їа(r)Ја ¬¬л}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=#0Then ch2:=ReadKey;
Case ch1 of#0: Case ch2 of#72: BeginIf Npos>1ThenBegin
DrawWin(menu[Npos],30);
Npos:=Npos-1;
DrawWin(menu[Npos],94);
End;
End;
#80: BeginIf Npos<5ThenBegin
DrawWin(menu[Npos],30);
Npos:=Npos+1;
DrawWin(menu[Npos],94);
End;
End;
End;
#13: BeginCase Npos of1: 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 of1: BeginIf (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: BeginIf c1<>0Then 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 of1: BeginIf (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 of1: 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: BeginIf c1<>0Then OutputDecimalFraction(c1,2,11,9,12)
Else InputDecimalFraction(st1,c1,err,2,11,9,12);
Operation(7,11,9,12,'+');
Case n1 of1: 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 of1: BeginIf (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 of1: 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: BeginIf c1<>0Then OutputDecimalFraction(c1,2,11,9,12)
Else InputDecimalFraction(st1,c1,err,2,11,9,12);
Operation(7,11,9,12,'-');
Case n1 of1: 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 of1: BeginIf (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 of1: 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: BeginIf c1<>0Then OutputDecimalFraction(c1,2,11,9,12)
Else InputDecimalFraction(st1,c1,err,2,11,9,12);
Operation(7,11,9,12,'*');
Case n1 of1: 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 of1: BeginIf (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 of1: 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: BeginIf c1<>0Then OutputDecimalFraction(c1,2,11,9,12)
Else InputDecimalFraction(st1,c1,err,2,11,9,12);
Operation(7,11,9,12,'/');
Case n1 of1: 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=1ThenBeginIf (a<>0) And (b<>0) ThenBegin
a:=a1;
b:=b1;
End;
If c<>0ThenBegin
c:=c1;
str(c,st);
End;
Window(1,7,80,25);
TextAttr:=7*16;
Clrscr;
End;
If answer=2ThenBeginIf (a<>0) and (b<>0) ThenBegin
a1:=a;
b1:=b;
End;
If c<>0ThenBegin
c1:=c;
str(c1,st1);
End;
Window(1,7,80,25);
Textattr:=7*16;
Clrscr;
End;
If answer=3ThenBegin
Window(1,7,80,25);
Textattr:=7*16;
Clrscr;
a1:=0;
b1:=0;
c1:=0;
End;
If answer=4ThenWhilenot EOF(Protokol) doBegin
Readln(Protokol,a1,b1,c1,a,b,c);
Writeln(a1,b1,c1,a,b,c);
End;
End;
End;
Until answer=5;
Close(Protokol);
End.
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.