Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses sysutils,math;
- type
- TS=record
- s1,s2:string;
- end;
- var
- fl,k,i:longint;
- n,n1,n2:extended;
- ch:char;
- s,s0:string;
- ss:TS;
- procedure help;
- Begin
- if fl=0 then begin
- writeln('Format input:');
- writeln('4+5');
- writeln('5-9');
- writeln('3*5.7');
- writeln('8.0/7');
- writeln('2^10');
- writeln('sqrt 25');
- writeln('cos 0.5');
- writeln('sin 1');
- write('>>> ');end
- else write('>>> ');
- fl:=1;
- End;
- procedure vivod;
- Begin
- writeln(s0);
- End;
- procedure probel(ss:TS);
- Begin
- n:=strtofloat(ss.s2);
- case ss.s1 of
- 'sqrt':n:=(sqrt(n));
- 'cos':n:=(cos(n));
- 'sin':n:=(sin(n));
- end;
- s0:=floattostr(n);
- vivod;
- End;
- procedure raschot(ss:TS);
- Begin
- if ch=' ' then probel(ss)
- else
- begin
- n1:=strtofloat(ss.s1);
- n2:=strtofloat(ss.s2);
- case ch of
- '+':n:=n1+n2;
- '-':n:=n1-n2;
- '*':n:=n1*n2;
- '/':n:=n1/n2;
- '^':n:=power(n1,n2);
- end;
- s0:=floattostr(n);
- vivod;
- end;
- End;
- function vvod:TS;
- Begin
- help;
- readln(s);
- if s='exit' then halt;
- i:=0;ch:=#0;k:=0;
- while i<length(s) do
- begin
- i:=i+1;
- if (s[i]='+')or(s[i]='-')or(s[i]='*')or(s[i]='/')or(s[i]='^')or(s[i]=' ')
- then begin ch:=s[i];k:=i;i:=length(s);end;
- end;
- ss.s1:=copy(s,1,k-1);
- ss.s2:=copy(s,k+1,length(s)-k);
- vvod:=ss;
- End;
- BEGIN
- while(true)do raschot(vvod);
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement