1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59:
| procedure TForm1.btnStartClick(Sender: TObject);
function CalcSide(var Side: Single; const Side1, Side2, Volume, Diagonal, Surface: Single; const Side1Valid, Side2Valid, VolumeValid, DiagonalValid, SurfaceValid: Boolean): Boolean; begin Result := True; if VolumeValid and Side1Valid and Side1Valid and (Side1 * Side2 <> 0) then Side := Volume / (Side1 * Side2) else if SurfaceValid and Side1Valid and Side2Valid and (Side1 + Side2 <> 0) then Side := ((Surface / 2) - (Side1 * Side2)) / (Side1 + Side2) else if Side1Valid and Side2Valid and DiagonalValid then Side := Sqrt(Sqr(Diagonal) - Sqr(Side1) - Sqr(Side2)) else Result := False; end;
var a, b, c, d, v, o: Single; av, bv, cv, dv, vv, ov: Boolean; begin av := TryStrToFloat(edtSideA.Text, a); bv := TryStrToFloat(edtSideB.Text, b); cv := TryStrToFloat(edtSideC.Text, c); dv := TryStrToFloat(edtDiagonal.Text, d); vv := TryStrToFloat(edtVolume.Text, v); ov := TryStrToFloat(edtSurface.Text, o);
repeat if not av then av := CalcSide(a, b, c, v, d, o, bv, cv, vv, dv, ov); if not bv then bv := CalcSide(b, a, c, v, d, o, av, cv, vv, dv, ov); if not cv then cv := CalcSide(c, a, b, v, d, o, av, bv, vv, dv, ov); if not dv and av and bv and cv then begin d := Sqrt(Sqr(a) + Sqr(b) + Sqr(c)); dv := True; end; if not ov and av and bv and cv then begin o := 2 * (a * b + a * c + b * c); ov := True; end; if not vv and av and bv and cv then begin v := a * b * c; vv := True; end; until av and bv and cv and dv and ov and vv; memResult.Visible := True; memResult.Clear; memResult.Lines.Add('Seitenlänge a ' + FloatToStrF(a, fffixed, 10,2)); memResult.Lines.Add('Seitenlänge b ' + FloatToStrF(b, fffixed, 10,2)); memResult.Lines.Add('Seitenlänge c ' + FloatToStrF(c, fffixed, 10,2)); memResult.Lines.Add('Diagonale d ' + FloatToStrF(d, fffixed, 10,2)); memResult.Lines.Add('Volumen V ' + FloatToStrF(v, fffixed, 10,2)); memResult.Lines.Add('Oberfläche O ' + FloatToStrF(o, fffixed, 10,2)); end; |