| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 539 人关注过本帖
标题:请教次程序是否有错,谢谢!
只看楼主 加入收藏
jiaojiaoboy
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-9
收藏
 问题点数:0 回复次数:0 
请教次程序是否有错,谢谢!
unit MainFrm;

interface


uses
   Windows,Messages,Sysutils,Classes,Graphics,Controls,Forms,Dialogs,Buttons,
   StdCtrls,ExtCtrls,Math,ComCtrl;


type
   TForm1=class(TForm)
      Panel1:TPanel;
      Panel2:TPanel;
      Panel3:TPanel;
      Label1:TLabel;
      Label1:TLabel;
      Label2:TLabel;
      Label3:TLabel;
      Label4:TLabel;
      Label5:TLabel;
      edt_A:TEdit;
      edt_B:TEdit;
      edt_H0:TEdit;
      edt_R:TEdit;
      Label6:TLabel;
      Label7:TLabel;
      edt_BEnd:TEdit;
      sbtn_Edit:TSpeedButton;
      sbtn_Undo:TSpeedButton;
      sbtn_Back:TSpeedButton;
      sbtn_Save:TSpeedButton;
      Label8:TLabel;
      edt_l:TEdit;
      procedure sbtn_EditClick(Sender:TObject);
      procedure sbtn_UndoClick(Sender:TObject);
      procedure FormShowClick(Sender:TObject);
      procedure sbtn_BackClick(Sender:TObject);
      procedure sbtn_SaveClick(Sender:TObject);
   private
      {Private declarations}
   public
      {Public declarations}
   end;


var
    Form1:TForm1;
implementation


var
   B,A:array of real;
   H0,R,h,k1,k2,k3,k4,1:real;
   i:integer;
   //A:real;

  {$R*.DFM}

  procedure TForm1.sbtn_EditClick(Sender:TObject);
  begin
    Panel1.Enabled:=True;
    Panel2.Enabled:=False;

    edt_A.SetFocus;
  end;


     procedure TForm1.sbtn_UndoClick(Sender:TObject);
     begin
        edt_A.Text:=";
        edt_B.Text:=";
        edt_H0.Text:=";
        edt_R.Text:=";
        edt_BEnd.Text:=";
        edt_1.Text:=";
        //edt_n.Text:=";
        Panel1.Enabled:=False;
        Raise Exception.Create('请重新赋值!');
     end;


     procedure TForm1.FormShow(Sender:TObject);
     begin
         Panel1.Enabled:=False;
         Panel2.Enabled:=False;
     end;


     procedure TForm1.sbtn_BackClick(Sender:TObject);
     begin
          setlength(A,300);
          setlength(B,300);
          if edt_A.Text="then
             Raise Exception.Create('请为A赋值!');
          if edt_B.Text="then
             Raise Exception.Create('请为B赋值!');
          if edt_H0.Text="then
             Raise Exception.Create('请为H0赋值!');
          if edt_R.Text="then
             Raise Exception.Create('请为R赋值!');
          if edt_1.Text="then
             Raise Exception.Create('请为1赋值!');
          //读取初值
             A[0]:=StrToFloat(Trim(edt_A.Text));
             B[0]:=StrToFloat(Trim(edt_B.Text));
             H0  :=StrToFloat(Trim(edt_H0.Text));
             R   :=StrToFloat(Trim(edt_A.Text));
             1   :=StrToFloat(Trim(edt_A.Text));
             //n   :=StrToFloat(Trim(edt_A.Text));
          //读取初值

              i:=0
              h:=1*3.1415926/(200*180);

              if(A[0]<0)or(A[0]>(1*3.1415926/180))then
                 Raise Exception.Create('初始值A超出范围,请重新赋值');
              While(A[i]<(1*3.1415926/180))do
              begin
                 k1:=0.014*0.014*9.81*R*B[i]*Power(2/B[i]+1/H0,4/3)-B[i]/(2*3.1415926-A[i]);
                 k2:=0.014*0.014*9.81*R*(B[i]+h*k1/2)*Power((2/B[i]+h*k1/2)+1/H0,4/3)-(B[i]+h*k1/2)/(2*3.1415926-(A[i]+h/2));
                 k3:=0.014*0.014*9.81*R*(B[i]+h*k2/2)*Power((2/B[i]+h*k2/2)+1/H0,4/3)-(B[i]+h*k2/2)/(2*3.1415926-(A[i]+h/2));
                 k4:=0.014*0.014*9.81*R*(B[i]+h*k3)*Power((2/B[i]+h*k3)+1/H0,4/3)-(B[i]+h*k3)/(2*3.1415926-(A[i]+h));
                 B[i+1]:=B[i]+h*(k1+2*k2+2*k3+k4)/6;
                 i:=i+1
                 A[i]:=A[i-1]+h;
              end;
                 edt_BEnd.Text:=FloatToStr(B[i]);
              end;


              procedure TForm1.sbtn_SaveClick(Sender:TOjbect);
              var
                  MyTextFile:TextFile;
                  j:integer;
                  s:String;
              begin
                  AssignFile(MyTextFile,'C:\Documents and Settings\Administrator\桌面\数据.txt');
                  Rewrite(MyTextFile);
                  try
                     for j:=0 to i do
                     begin
                        if(B[j]>=300)then
                        begin
                           s:='计算次数:';
                           //writeln(MyTextFile,s,j,A[j],B[j]);
                           writeln(MyTextFile,s,j);
                           writeln(MyTextFile,'    ',FormatFloat('0.0000000',B[j]));
                        end;
                     end;
                 finally
                     CloseFile(MyTextFile);
                 end;
            end;
end.
搜索更多相关主题的帖子: Windows 
2012-08-09 16:45
快速回复:请教次程序是否有错,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037443 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved