怎么计算这个值“((3*4)+(8/4))*2+3”
来源: 互联网 发布时间:2015-09-23
本文导语: 这是个变的值,,建设从JTestField中输入“((3*4)+(8/4))*2+3” 然后就可以计算出值来,, 具体怎么做,? | { 程序:四则运算计算器 作者:tomm For more Information ,please visit http://www.tommstudio.com } unit jsq; i...
这是个变的值,,建设从JTestField中输入“((3*4)+(8/4))*2+3”
然后就可以计算出值来,,
具体怎么做,?
然后就可以计算出值来,,
具体怎么做,?
|
{
程序:四则运算计算器
作者:tomm
For more Information ,please visit http://www.tommstudio.com
}
unit jsq;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons,ExtCtrls,urlmon;
const MaxElements=100; //maximum char in stack;
type TStack=class
private
SData:array[1..MaxElements] of string; //stack data
public
IsEmpty:boolean; //it is an empty stack
TopPointer:integer; //the top pointer of the stack;
procedure Init;
function GetElement(var data:string;i:integer):boolean; //get data from stack
function PopElement(var data:string):boolean; //popup data
function PushElement(data:string):boolean; //push data
end;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
SpeedButton20: TSpeedButton;
Panel1: TPanel;
SpeedButton18: TSpeedButton;
SpeedButton19: TSpeedButton;
SpeedButton21: TSpeedButton;
SpeedButton22: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure SpeedButton20Click(Sender: TObject);
procedure SpeedButton19Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton22Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure StoreExpression(exp:string;mystack:TStack); //save expression
procedure TransformExpression(sourceStack,targetStack:TStack); //transform
function Calculate(rStack:TStack;var Aresult:real):boolean; //calculate
var
Form1: TForm1;
ExpressionStack,tempStack,ReverseStack:TStack;
implementation
{$R *.DFM}
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if panel1.Caption='Syntax Error' then SpeedButton17.Click;
if TSpeedbutton(sender).caption='+/-' then begin //+/-的处理
if panel1.caption='0' then exit;
if panel1.Caption[1]='-' then panel1.caption:=copy(panel1.caption,2,length(panel1.caption)) else panel1.Caption:='-'+panel1.Caption;
exit;
end;
if (TSpeedbutton(Sender).caption[1] in ['0'..'9','(']) and (panel1.Caption='0') then panel1.Caption:=''; //输入数字的处理
panel1.Caption:=panel1.Caption+TSpeedButton(Sender).caption;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ExpressionStack:=TStack.Create;
tempStack:=TStack.Create;
ReverseStack:=TStack.Create;
ExpressionStack.Init;
tempStack.Init;
ReverseStack.Init;
end;
function TStack.GetElement(var data:string;i:integer):boolean;
begin
if (i>TopPointer) or (i
程序:四则运算计算器
作者:tomm
For more Information ,please visit http://www.tommstudio.com
}
unit jsq;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons,ExtCtrls,urlmon;
const MaxElements=100; //maximum char in stack;
type TStack=class
private
SData:array[1..MaxElements] of string; //stack data
public
IsEmpty:boolean; //it is an empty stack
TopPointer:integer; //the top pointer of the stack;
procedure Init;
function GetElement(var data:string;i:integer):boolean; //get data from stack
function PopElement(var data:string):boolean; //popup data
function PushElement(data:string):boolean; //push data
end;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
SpeedButton20: TSpeedButton;
Panel1: TPanel;
SpeedButton18: TSpeedButton;
SpeedButton19: TSpeedButton;
SpeedButton21: TSpeedButton;
SpeedButton22: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure SpeedButton20Click(Sender: TObject);
procedure SpeedButton19Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton22Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure StoreExpression(exp:string;mystack:TStack); //save expression
procedure TransformExpression(sourceStack,targetStack:TStack); //transform
function Calculate(rStack:TStack;var Aresult:real):boolean; //calculate
var
Form1: TForm1;
ExpressionStack,tempStack,ReverseStack:TStack;
implementation
{$R *.DFM}
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if panel1.Caption='Syntax Error' then SpeedButton17.Click;
if TSpeedbutton(sender).caption='+/-' then begin //+/-的处理
if panel1.caption='0' then exit;
if panel1.Caption[1]='-' then panel1.caption:=copy(panel1.caption,2,length(panel1.caption)) else panel1.Caption:='-'+panel1.Caption;
exit;
end;
if (TSpeedbutton(Sender).caption[1] in ['0'..'9','(']) and (panel1.Caption='0') then panel1.Caption:=''; //输入数字的处理
panel1.Caption:=panel1.Caption+TSpeedButton(Sender).caption;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ExpressionStack:=TStack.Create;
tempStack:=TStack.Create;
ReverseStack:=TStack.Create;
ExpressionStack.Init;
tempStack.Init;
ReverseStack.Init;
end;
function TStack.GetElement(var data:string;i:integer):boolean;
begin
if (i>TopPointer) or (i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!