Advertisement
Guest User

calc to anon

a guest
May 2nd, 2015
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uses sysutils,math;
  2. type
  3.         TS=record
  4.         s1,s2:string;
  5.         end;
  6. var
  7. fl,k,i:longint;
  8. n,n1,n2:extended;
  9. ch:char;
  10. s,s0:string;
  11. ss:TS;
  12.  
  13. procedure help;
  14. Begin
  15. if fl=0 then begin
  16. writeln('Format input:');
  17. writeln('4+5');
  18. writeln('5-9');
  19. writeln('3*5.7');
  20. writeln('8.0/7');
  21. writeln('2^10');
  22. writeln('sqrt 25');
  23. writeln('cos 0.5');
  24. writeln('sin 1');
  25. write('>>> ');end
  26.         else write('>>> ');
  27. fl:=1;
  28. End;
  29.  
  30. procedure vivod;
  31. Begin
  32. writeln(s0);
  33. End;
  34.  
  35. procedure probel(ss:TS);
  36. Begin
  37. n:=strtofloat(ss.s2);
  38. case ss.s1 of
  39.         'sqrt':n:=(sqrt(n));
  40.         'cos':n:=(cos(n));
  41.         'sin':n:=(sin(n));
  42.         end;
  43. s0:=floattostr(n);
  44. vivod;
  45. End;
  46.  
  47. procedure raschot(ss:TS);
  48. Begin
  49. if ch=' ' then probel(ss)
  50.         else
  51.         begin
  52. n1:=strtofloat(ss.s1);
  53. n2:=strtofloat(ss.s2);
  54. case ch of
  55.         '+':n:=n1+n2;
  56.         '-':n:=n1-n2;
  57.         '*':n:=n1*n2;
  58.         '/':n:=n1/n2;
  59.         '^':n:=power(n1,n2);
  60.         end;
  61. s0:=floattostr(n);
  62. vivod;
  63.         end;
  64. End;
  65.  
  66. function vvod:TS;
  67. Begin
  68. help;
  69. readln(s);
  70. if s='exit' then halt;
  71. i:=0;ch:=#0;k:=0;
  72. while i<length(s) do
  73.         begin
  74.         i:=i+1;
  75.         if (s[i]='+')or(s[i]='-')or(s[i]='*')or(s[i]='/')or(s[i]='^')or(s[i]=' ')
  76.                 then begin ch:=s[i];k:=i;i:=length(s);end;
  77.         end;
  78. ss.s1:=copy(s,1,k-1);
  79. ss.s2:=copy(s,k+1,length(s)-k);
  80. vvod:=ss;
  81. End;
  82.  
  83.  
  84.  
  85. BEGIN
  86. while(true)do raschot(vvod);
  87. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement