比如说有  A B C D E 五个变量,要能根据 + - * / ,还有 sin、cos、tan、PI、 sqrt 、LOG 等函数自动生成公式,比如说:sin(A)+ cos(A+B)* PItan(sqrt(A*D)- 2* E)+ LOG(C* D*E)...等等说明白了吧?
谢谢

解决方案 »

  1.   

    http://topic.csdn.net/u/20100504/09/6a7a5b87-296b-435c-94cc-bc0b2b045f25.html
      

  2.   

    http://www.codesoso.com/code/math_expression_parser.aspx
      

  3.   

    to icansaymyabc:
    这不是作业to gefangliang:
    我要的是随机自动生成公式的。根据公式计算这个倒是不需要。
      

  4.   

    to ustbwuyi:
    可以给个简单一点的例子吗,谢谢!
      

  5.   

    嗯,这就算完了,不要那些函数了,可能算起来会比较慢
    谢谢大家了,虽然没帮上什么忙,不过也挺热心的,等有时间就来结贴吧,见者有份function dx(n:Integer=-1):string;
    var
      i,j,tn,mx:Integer;
    begin
      Randomize;  mx:= 28;
      i:= Random(mx);
      j:= Random(mx);  tn:= n;
      if tn=-1 then
      begin
      repeat
      tn:= Random(mx)+12;
      until tn<=mx;
      end;  case tn of
      0:Result:= 'A';
      1:Result:= 'B';
      2:Result:= 'C';
      3:Result:= 'D';
      4:Result:= 'E';
      5:Result:= 'HZ';
      6:Result:= 'KD';
      7:Result:= 'HW';
      8:Result:= 'QW';
      9:Result:= 'PJ';
      10:Result:= 'DS';
      11:Result:= 'XS';
      12:Result:= dx(Random(11))+ dx(Random(11));//两个数合并
      13:Result:= dx(i) +'+'+ dx(j);
      14:Result:= dx(i) +'-'+ dx(j);
      15:Result:= dx(i)+'*'+ dx(j);
      16:Result:= dx(i)+'/'+ dx(j);
      17:Result:= dx(Random(16)) + '+ 0.618';
      18:Result:= dx(Random(16)) + '- 0.618';
      19:Result:= dx(Random(16)) + '* 0.618';
      20:Result:= dx(Random(16)) + '/ 0.618';
      21:Result:= '0.618/'+ dx(Random(16));
      22:Result:= '0.618-'+ dx(Random(16));
      23:Result:= dx(Random(16)) +'+'+ IntToStr(Random(100)+1);
      24:Result:= dx(Random(16)) +'-'+ IntToStr(Random(100)+1);
      25:Result:= dx(Random(16)) +'*'+ IntToStr(Random(100)+1);
      26:Result:= dx(Random(16)) +'/'+ IntToStr(Random(100)+1);
      27:Result:= IntToStr(Random(100)+1)+'-'+dx(Random(16));
      28:Result:= IntToStr(Random(100)+1)+'/'+dx(Random(16));
      end;
    end;调用:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:Integer;
      ts:string;
    begin
      //
      Memo1.Clear;
      for i:= 0 to 100 do
      begin
      repeat
      ts:= dx;
      until (Length(ts)>15) and (Length(ts)<40);  Memo1.Lines.Add(ts);
      end;