Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Quader Berechnung mit je drei Variablen (https://www.delphipraxis.net/132765-quader-berechnung-mit-je-drei-variablen.html)

JonesAdams 19. Apr 2009 08:47


Quader Berechnung mit je drei Variablen
 
Hi zusammen!

Ich wollte eins von diesen Programmen für die Quaderberechnung entwickeln, mit dem man durch Angabe von nur drei Werten alle weiteren bekomme.


Ich hab' meine grauen Zellen schon aktiviert und das hier zu Papier gebracht:

a (Edit1), b(Edit2) und c(Edit3) sind die Seitenlängen des Quaders;
d(Edit4) ist die Raumdiagonale;
v(Edit5) ist das Volumen
und o(Edit6) die Oberfläche.

Einen Quader könnte man ja vollkommen mit drei der Werte berechnen. Doch egal, welche drei Editfelder (die ursprünglich leer sind), gefüllt werden, das Programm friert ein.


Delphi-Quellcode:
unit QUADERSPECIAL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var a,b,c,d,v,o: real;
begin
if Edit1.Text <> '' then
 begin
 a:=strtofloat(Edit1.Text);
 end;
if Edit2.Text <> '' then
 begin
 b:=strtofloat(Edit2.Text);
 end;
if Edit3.Text <> '' then
 begin
 c:=strtofloat(Edit3.Text);
 end;
if Edit4.Text <> '' then
 begin
 d:=strtofloat(Edit4.Text);
 end;
if Edit5.Text <> '' then
 begin
 v:=strtofloat(Edit5.Text);
 end;
if Edit6.Text <> '' then
 begin
 o:=strtofloat(Edit6.Text);
 end;

repeat
begin
 if b=0 then
  begin
  b:=v/(a*c);
  b:=((o/2)-(a*c))/(a+c);

   if (a<>0) and (c<>0) and (d<>0) then
    begin
    b:=sqrt(sqr(d)-sqr(a)-sqr(c));
    end;

  end;


 if a=0 then
  begin
  a:=v/(b*c);
  a:=((o/2)-(b*c))/(b+c);

   if (b<>0) and (c<>0) and (d<>0) then
    begin
    a:=sqrt(sqr(d)-sqr(b)-sqr(c));
    end;

  end;


 if c=0 then
  begin
  c:=v/(b*a);
  c:=((o/2)-(b*a))/(b+a);

   if (a<>0) and (b<>0) and (d<>0) then
    begin
    c:=sqrt(sqr(d)-sqr(b)-sqr(a));
    end;

  end;


 if d=0 then
  begin

   if (a<>0) and (c<>0) and (d<>0) then
    begin
    d:=sqrt(sqr(a)+sqr(d)+sqr(c));
    end;

  end;

 if o=0 then
  begin
  o:=2*(a*b+a*c+b*c);
  end;

 if v=0 then
 begin
 v:=a*b*c;
 end;

end;
until (a<>0) and (b<>0) and (c<>0) and (d<>0) and (o<>0) and (v<>0);
memo1.Visible:= True;
Memo1.Clear;
Memo1.Lines.Add('Seitenlänge a        ' + FloatToStrF(a, fffixed, 10,2));
Memo1.Lines.Add('Seitenlänge b        ' + FloatToStrF(b, fffixed, 10,2));
Memo1.Lines.Add('Seitenlänge c        ' + FloatToStrF(c, fffixed, 10,2));
Memo1.Lines.Add('Diagonale d          ' + FloatToStrF(d, fffixed, 10,2));
Memo1.Lines.Add('Volumen V            ' + FloatToStrF(v, fffixed, 10,2));
Memo1.Lines.Add('Oberfläche O         ' + FloatToStrF(o, fffixed, 10,2));
end;

end.

jaenicke 19. Apr 2009 08:55

Re: Quader Berechnung mit je drei Variablen
 
Crossposts solltest du verlinken, damit man im jeweils anderen Forum schauen kann, ob schon Antworten vorliegen.
http://www.delphi-forum.de/viewtopic.php?p=558813

Wobei gerade wenn du bereits eine Antwort bekommen hast, ein Crosspost ja wohl etwas überflüssig ist...


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz