home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CALC / DO.ZIP / DO.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-10-08  |  6.9 KB  |  295 lines

  1. Program MathLine;
  2.  
  3. {Program by Dan Holloway, 39 Douglas drive     Herrin, Illinois 62948}
  4.  
  5. {An exercise in the use of command line parameters}
  6.  
  7. Uses Dos, Crt;
  8.  
  9. Var
  10.  I1, I2, I3, I4, I5, I6     :  real;
  11.  P1, P2, P3, P4, P5, P6     :  string;
  12.  Code, I, A, B              :  integer;
  13.  Answer, X , Y, Z           :  real;
  14.  Fact, Factorials           :  real;
  15.  
  16. {-----------------------------------------------------------------------------}
  17. procedure KickUp(var str : string);
  18.  
  19. {This procedure converts string to all uppercase}
  20.  
  21.  Var
  22.  I   : integer;
  23. begin
  24.  for I := 1 to length(str) do
  25.   str[I] := UpCase (str[I]);
  26.  end;
  27.  
  28. {-----------------------------------------------------------------------------}
  29. procedure KickDown(var str : string);
  30.  
  31. {This procedure converts string to all lowercase}
  32.  
  33.  Var
  34.   I : integer;
  35. begin
  36.   for I := 1 to Length(str) do
  37.    if (str[I] >= 'A') and (str[I] <= 'Z') then
  38.    str[I] := Chr(Ord(str[I]) + 32)
  39. end;
  40.  
  41. {-----------------------------------------------------------------------------}
  42.  
  43. procedure GraphYesNo;  {This procedure could easily be converted to}
  44.  var                   {a function to produce color only if graphics card}
  45.   C : integer;         {is available. exmp : if GraphYesNo then TextColor(B)}
  46. begin
  47.   if mem[0:$449] = 7 then
  48.   writeln('Monochrome card'); {optional statement}
  49.   if mem[0:$449] <> 7 then
  50.   writeln('Color graphics adapter'); {optional statement}
  51.   C := mem[0:449];
  52.   writeln('Contents of location -mem- : ',C);  {optional statement}
  53. end;
  54.  
  55. {-----------------------------------------------------------------------------}
  56.  
  57. procedure SoundOff;
  58. Var I : integer;
  59. Begin
  60.   I := 1400;
  61.   Repeat
  62.     Sound(I);
  63.     Delay(1);
  64.     I := I + 1;
  65.   Until I = 1410;
  66. NoSound;           {If you forget this the sound keeps onnnnnnnn !}
  67. end;
  68.  
  69. {-----------------------------------------------------------------------------}
  70.  
  71. procedure Hint;
  72. Begin
  73.     GraphYesNo;
  74.     Randomize;
  75.     B := Random(3) + 10;  {Add or restrict colors used}
  76.     TextColor(B);
  77.   writeln('                 Syntax as follows ....');
  78.   writeln('                 Multiply    : do 3 x 4');
  79.   writeln('                 Divide      : do 3 / 4');
  80.   writeln('                 Add         : do 3 + 4');
  81.   writeln('                 Subtract    : do 3 - 4');
  82.   writeln('                 Power       : do power 2 5 [ where 2 = power ]');
  83.   writeln('                 Root        : do root 3 9 [ where 3 = root ]');
  84.   writeln('                 Factorial   : do factorial 5');
  85.   SoundOff;
  86.   GraphYesNo;
  87.   GoToXY(1,25);
  88.   Halt;
  89. end;
  90.  
  91. {-----------------------------------------------------------------------------}
  92.  
  93. procedure Null;
  94. Begin
  95.   GraphYesNo;
  96.   begin
  97.     Randomize;
  98.     B := Random(3) + 10;
  99.     TextColor(B);
  100.   end;
  101.   writeln('             for help type  DO ?');
  102.   writeln('__________________________________________________');
  103.   SoundOff;
  104.   GoToXY(1,25);
  105.   Halt;
  106. end;
  107.  
  108. {-----------------------------------------------------------------------------}
  109.  
  110. procedure Multiply;
  111. Begin
  112.  Answer := I1 * I3;
  113.   GraphYesNo;
  114.   begin
  115.     Randomize;
  116.     B := Random(3) + 10;
  117.     TextColor(B)
  118.   end;
  119.  writeln('                  ',I1:2:3,' times ',I3:2:3,' is : ',Answer:6:6);
  120.  SoundOff;
  121.  writeln;
  122.  writeln;
  123.  Halt;
  124. end;
  125.  
  126. {-----------------------------------------------------------------------------}
  127.  
  128. procedure Divide;
  129. Begin
  130.   GraphYesNo;
  131.   begin
  132.     Randomize;
  133.     B := Random(3) + 10;
  134.     TextColor(B)
  135.   end;
  136.   if I3 > 0 then
  137.   begin
  138.    Answer := I1 / I3;
  139.    writeln('                ',I1:2:3,' divided by ',I3:2:3,' is : ',Answer:6:6);
  140.   end;
  141.    if I3 = 0 then writeln('Division by zero not allowed !');
  142.    SoundOff;
  143.    writeln;
  144.    writeln;
  145.    Halt;
  146. end;
  147.  
  148. {-----------------------------------------------------------------------------}
  149.  
  150. procedure Root;
  151. Begin
  152.   GraphYesNo;
  153.   begin
  154.     Randomize;
  155.     B := Random(3) + 10;
  156.     TextColor(B)
  157.   end;
  158.     if I3 <= 0 then
  159.     begin
  160.       writeln('Cannot take root of negative number or zero !');
  161.       writeln;
  162.       writeln;
  163.       Halt;
  164.     end;
  165.     if I2 = 0 then
  166.     begin
  167.        writeln('Root cannot be a zero !');
  168.     end;
  169.   if I2 > 0 then
  170.   begin
  171.     X := ln(I3);
  172.     Y := X / I2;
  173.     Z := Exp(Y);
  174.     writeln('               root ',I2:2:3,' of ',I3:2:3,' is : ',Z:6:6);
  175.     SoundOff;
  176.     writeln;
  177.     writeln;
  178.     Halt;
  179.   end;
  180. end;
  181.  
  182. {-----------------------------------------------------------------------------}
  183.  
  184. procedure Power;
  185. Begin
  186.   GraphYesNo;
  187.   begin
  188.     Randomize;
  189.     B := Random(3) + 10;
  190.     TextColor(B)
  191.   end;
  192.   if I3 <= 0 then
  193.   begin
  194.    writeln('Base numbers cannot be negative or zero !');
  195.    writeln;
  196.    writeln;
  197.    Halt;
  198.   end;
  199.   if I3 > 0 then
  200.   begin
  201.     X := ln(I3);
  202.     Y := X * I2;
  203.     Z := Exp(Y);
  204.     writeln('               ',I3:2:3,' to power ',I2:2:3,' is : ',Z:6:6);
  205.     SoundOff;
  206.     writeln;
  207.     writeln;
  208.     Halt;
  209.   end;
  210. end;
  211.  
  212. {-----------------------------------------------------------------------------}
  213.  
  214. procedure Add;
  215. Begin
  216.   Answer := I1 + I3;
  217.   GraphYesNo;
  218.   begin
  219.     Randomize;
  220.     B := Random(3) + 10;
  221.     TextColor(B)
  222.   end;
  223.   writeln('                 The sum of ',I1:2:6,' and ',I3:2:3,' is : ',Answer:3:9);
  224.   SoundOff;
  225.   writeln;
  226.   writeln;
  227.   Halt;
  228. end;
  229.  
  230. {-----------------------------------------------------------------------------}
  231.  
  232. procedure Subtract;
  233. Begin
  234.   Answer := I1 - I3;
  235.   GraphYesNo;
  236.   begin
  237.     Randomize;
  238.     B := Random(3) + 10;
  239.     TextColor(B)
  240.   end;
  241.   writeln('                 ',I1:2:3,' minus ',I3:2:3,' is : ',Answer:3:6);
  242.   SoundOff;
  243.   writeln;
  244.   writeln;
  245.   Halt;
  246. end;
  247.  
  248. {-----------------------------------------------------------------------------}
  249.  
  250. procedure Factorial;
  251. Begin
  252.    Fact := 1;
  253.     for I := 2 to Round(I2) do
  254.     Fact := Fact * I;
  255.    Factorials := Fact;
  256.   GraphYesNo;
  257.   begin
  258.     Randomize;
  259.     B := Random(3) + 10;
  260.     TextColor(B)
  261.   end;
  262.    writeln('                factorial ',I2:2:3,' is : ',Factorials:2:3);
  263.    SoundOff;
  264.    writeln;
  265.    writeln;
  266.    Halt;
  267. end;
  268.  
  269. {-----------------------------------------------------------------------------}
  270.  
  271. Begin
  272.   P1 := ParamStr(1);  {Assign P1 as the first parameter, P2 the second, etc.}
  273.   P2 := ParamStr(2);
  274.   P3 := ParamStr(3);
  275.   P4 := ParamStr(4);
  276.   P5 := ParamStr(5);
  277.   P6 := ParamStr(6);
  278.   Val(P1, I1, Code);  {P1 is a string value. Use Val to allow integer value.}
  279.   Val(P2, I2, Code);  {The integer value is used in the procedures to do the}
  280.   Val(P3, I3, Code);  {calculations.  Simple, but it looks slick !}
  281.   Val(P4, I4, Code);
  282.   Val(P5, I5, Code);
  283.   Val(P6, I6, Code);
  284.   KickUp(P2);
  285.   If P2 = 'X' then Multiply;
  286.   If P2 = '/' then Divide;
  287.   KickUp(P1);
  288.   if P1 = '' then Null;
  289.   if P1 = '?' then Hint;
  290.   if P1 = 'ROOT' then Root;
  291.   if P1 = 'POWER' then Power;
  292.   if P1 = 'FACTORIAL' then Factorial;
  293.   if P2 = ('+') then Add;
  294.   if P2 = ('-') then Subtract;
  295. end.