Delphi Recording Assistant for Dual

SITUATION

I wrote a class for equations of the second degree that looks like this. You can find the full class code here , but this is not very important for the question.

type
 TArrayOfDouble = array of array of double;

type
 TEqSecGrado = class
  private
   //variables
   a, b, c: double;
   delta: double;
   solutions: TArrayOfDouble;
   solRealCount: integer;
   solImaginaryCount: integer;
   class var currentIstances: integer;
   class var totalIstances: integer;
   //methods
   function getDelta(const vala, valb, valc: double): double; overload;
  public
   constructor Create(const a, b, c: double);
   destructor Destroy; override;
   //methods
   function getDelta: double; overload;
   function getSolutions: TArrayOfDouble; virtual;
   //properties
   property valueOfA: double read a;
   property valueOfB: double read b;
   property valueOfC: double read c;
   property realSolutionsCount: integer read solRealCount;
   property imaginarySolutionsCount: integer read solImaginaryCount;
   class property currentEquationsCount: integer read currentIstances;
   class property totalEquationsCount: integer read totalIstances;
 end;

I was thinking of creating a new type called TArrayOfDoublethat will contain a solution to my equation. In the main form, I use the class as follows:

procedure TForm3.Button1Click(Sender: TObject);
var solver: TEqSecGrado;
    soluzioni: TArrayOfDouble;
begin

 //f(x) = 3x^2 - x - 2 -> [sol.1 = 1 | sol.2 = -0,666666666666667]
 solver := TEqSecGrado.Create(3,-1,-2);

 try
  soluzioni := solver.getSolutions; 
  //soluzioni[0][0] = 1; soluzioni[0][1] = 0; 
  //soluzioni[1][0] = -0,666666666666667; soluzioni[1][1] = 0; 
 finally
  solver.Free;
 end;

end;

Now I have the results inside soluzioni, and I can output them. (I used the matrix, because in the first place I put the real solutions, in this case 1 and -0.67, and in the second sports immunological solutions if necessary).


Question

, . - soluzioni[a][b].toFraction. , .

type
 TSupport = record helper for Double
   function toFraction: string;
   function toString: string; //I have added this LATER
 end;

. TSupport toFraction, soluzioni [0] [0].toFraction, soluzioni [i] [0].String.

, toString, . ? , toString, .

, - , , ?

+4
1

, . ToString Double , Delphi RTL. , RTL .

:

. . , . Delphi (, ).

, , . , , , .

, :

  • , RTL .
  • .
+7

Source: https://habr.com/ru/post/1654269/


All Articles