Advertisement
peterzig

{PASCAL} Velocity Calculator

Jan 27th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.41 KB | None | 0 0
  1. program laz;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, SysUtils, CustApp
  10.   { you can add units after this };
  11.  
  12. type
  13.  
  14.   { TMyApplication }
  15.  
  16.   TMyApplication = class(TCustomApplication)
  17.   protected
  18.     procedure DoRun; override;
  19.   public
  20.     constructor Create(TheOwner: TComponent); override;
  21.     destructor Destroy; override;
  22.     procedure WriteHelp; virtual;
  23.   end;
  24.  
  25. { TMyApplication }
  26.  
  27. procedure TMyApplication.DoRun;
  28. var
  29.   ErrorMsg: String;
  30.   H, L, B, V, A, T, i,j , vx,vy,g,x,y,u: Real;
  31.   f:text;
  32.   abc,cba:String;
  33.  
  34. begin
  35.   // quick check parameters
  36.   ErrorMsg:=CheckOptions('h', 'help');
  37.   g:=10;
  38.   system.assign(f, 'dane.csv');
  39.   rewrite(f);
  40.  
  41.  writeLn('write value H, coordinate of the starting point');
  42.    begin
  43.     repeat
  44.     Readln(H);
  45.     if H<0 then
  46.     begin
  47.       writeLn('it can not be negative, write it one more time');
  48.       i:=0;
  49.     end
  50.     else if H>=0 then i:=1;
  51.     until i=1;
  52.     end;
  53.  
  54.   writeLn('write distance between starting point and wall');
  55.   begin
  56.     repeat
  57.     Readln(L);
  58.     if L<=0 then
  59.     begin
  60.       writeLn('it can not be negative, write it one more time');
  61.       i:=0;
  62.     end
  63.     else if L>0 then i:=1 ;
  64.     until i=1;
  65.   end;
  66.  
  67.     writeLn('write inclination of the bottom, between 0 and 90 degrees');
  68.   begin
  69.     repeat
  70.     Readln(B);
  71.     if (B<0) or (B>90) then
  72.     begin
  73.       writeLn('it must be between 0 and 90 degrees, write it one more time');
  74.       i:=0;
  75.     end
  76.     else if (B>=0) and (B<90) then i:=1 ;
  77.     until i=1;
  78.   end;
  79.  
  80.       writeLn('write starting, initial velocity');
  81.   begin
  82.     repeat
  83.     Readln(V);
  84.     if (V<0) then
  85.     begin
  86.       writeLn('do not write negative value');
  87.       i:=0;
  88.     end
  89.     else if (V>0) then i:=1 ;
  90.     until i=1;
  91.   end;
  92.  
  93.      writeLn('write inclination of the throw, between 0 ang 90 degrees');
  94.   begin
  95.     repeat
  96.     Readln(A);
  97.     if (A<0) or (A>90) then
  98.     begin
  99.       writeLn('it can not be negative, write it one more time');
  100.       i:=0;
  101.     end
  102.     else if (A>=0) and (A<90) then i:=1 ;
  103.     until i=1;
  104.   end;
  105.  
  106.        writeLn('increment time');
  107.   begin
  108.     repeat
  109.     Readln(T);
  110.     if (T<0)  then
  111.     begin
  112.       writeLn('it can not be negative, write it one more time');
  113.       i:=0;
  114.     end
  115.     else if (T>=0) then i:=1 ;
  116.     until i=1;
  117.   end;
  118.  
  119.   i:=0;
  120.  
  121.   y:=H;
  122.   x:=0;
  123.   Writeln(f, 'x',';', 'y');
  124.     Str(x:0:2,abc);
  125.   Str(y:0:2,cba);
  126.   Writeln(f, abc,';', cba);
  127.   repeat
  128.   i:=i+0.1;
  129.   vx:=V*(cos(A));
  130.   vy:=V*sin(A)-(g*i);
  131.   x:=(V*i*cos(A));
  132.   y:=H+(V*i*sin(A)-((g/2)*(i*i)));
  133.   u:=x*sin(B);
  134.  
  135.   V:=V*0.98;
  136.  
  137.   writeLn('');
  138.   writeLn(i:0:2,' time of experiment');
  139.    writeLn(V:0:2,' velocity in time');
  140.    writeLn(vx:0:2,' velocity vector vx');
  141.    writeLn(vy:0:2,' velocity vector vy');
  142.    writeLn(x:0:2, ' coordinate x');
  143.    writeLn(y:0:2, ' coordinate y');
  144.    writeLn(u:0:2, ' coordinate u');
  145.    Str(x:0:2,abc);
  146.    Str(y:0:2,cba);
  147.    Writeln(f, abc,';', cba);
  148.  
  149.    until (i>=T) or (y<=u) or (x>=L);
  150.    close(f);
  151.    if (i>=T) then
  152.    writeLn('end of time');
  153.    if y<=u then
  154.    writeLn('bottom was reached');
  155.    if x>=L then
  156.    writeLn('wall is reached');
  157.  
  158.  
  159.   readln(j);
  160.   close(f);
  161.  
  162. ;
  163.  
  164.   if ErrorMsg<>'' then begin
  165.     ShowException(Exception.Create(ErrorMsg));
  166.     Terminate;
  167.     Exit;
  168.   end;
  169.  
  170.   // parse parameters
  171.   if HasOption('h', 'help') then begin
  172.     WriteHelp;
  173.     Terminate;
  174.     Exit;
  175.   end;
  176.  
  177.   { add your program here }
  178.  
  179.   // stop program loop
  180.   Terminate;
  181. end;
  182.  
  183. constructor TMyApplication.Create(TheOwner: TComponent);
  184. begin
  185.   inherited Create(TheOwner);
  186.   StopOnException:=True;
  187. end;
  188.  
  189. destructor TMyApplication.Destroy;
  190. begin
  191.   inherited Destroy;
  192. end;
  193.  
  194. procedure TMyApplication.WriteHelp;
  195. begin
  196.   { add your help code here }
  197.   writeln('Usage: ', ExeName, ' -h');
  198. end;
  199.  
  200. var
  201.   Application: TMyApplication;
  202. begin
  203.   Application:=TMyApplication.Create(nil);
  204.   Application.Title:='My Application';
  205.   Application.Run;
  206.   Application.Free;
  207. end.
  208. program Project1;
  209.  
  210. {$mode objfpc}{$H+}
  211.  
  212. uses
  213.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  214.   cthreads,
  215.   {$ENDIF}{$ENDIF}
  216.   Classes, SysUtils, CustApp
  217.   { you can add units after this };
  218.  
  219. type
  220.  
  221.   { TMyApplication }
  222.  
  223.   TMyApplication = class(TCustomApplication)
  224.   protected
  225.     procedure DoRun; override;
  226.   public
  227.     constructor Create(TheOwner: TComponent); override;
  228.     destructor Destroy; override;
  229.     procedure WriteHelp; virtual;
  230.   end;
  231.  
  232. { TMyApplication }
  233.  
  234. procedure TMyApplication.DoRun;
  235. var
  236.   ErrorMsg: String;
  237. begin
  238.   // quick check parameters
  239.   ErrorMsg:=CheckOptions('h', 'help');
  240.   if ErrorMsg<>'' then begin
  241.     ShowException(Exception.Create(ErrorMsg));
  242.     Terminate;
  243.     Exit;
  244.   end;
  245.  
  246.   // parse parameters
  247.   if HasOption('h', 'help') then begin
  248.     WriteHelp;
  249.     Terminate;
  250.     Exit;
  251.   end;
  252.  
  253.   { add your program here }
  254.  
  255.   // stop program loop
  256.   Terminate;
  257. end;
  258.  
  259. constructor TMyApplication.Create(TheOwner: TComponent);
  260. begin
  261.   inherited Create(TheOwner);
  262.   StopOnException:=True;
  263. end;
  264.  
  265. destructor TMyApplication.Destroy;
  266. begin
  267.   inherited Destroy;
  268. end;
  269.  
  270. procedure TMyApplication.WriteHelp;
  271. begin
  272.   { add your help code here }
  273.   writeln('Usage: ', ExeName, ' -h');
  274. end;
  275.  
  276. var
  277.   Application: TMyApplication;
  278. begin
  279.   Application:=TMyApplication.Create(nil);
  280.   Application.Title:='My Application';
  281.   Application.Run;
  282.   Application.Free;
  283. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement