A ver si termino de averiguar cómo solucionar el último problema que tengo (manejarme con una TObjectList). Pero para ello faltan mínimo dos días de trabajo antes de comentar dudas jeje.
Si termino y el departamento de Matemáticas de la facultad me de el vistobueno conforme funcione como debería y esté más o menos completa puedo mirar de subir un enlace con el código entero. Que no es gran cosa pero me hace ilusión aportar algo ya que siempre me están ayudando
También se aceptan sugerencias para mejorar lo posteado
Código Delphi
[-]
interface
uses
Classes, SysUtils, Math, Dialogs;
type
TComplex = class(TObject)
protected
fRe:extended;
fImg:extended;
fModulo:extended;
fArgumento:extended;
function GetRe:string;
procedure SetRe(const AnRe: string);
function GetImg:string;
procedure SetImg(const AnImg: string);
function GetModulo:string;
procedure SetModulo(const AnModulo: string);
function GetArgumento:string;
procedure SetArgumento(const AnArgumento: string);
procedure GetRectangular;
procedure GetPolar;
public
constructor Create; overload;
constructor Crear(format:char; input1,input2:string);
property Re:string read GetRe write SetRe;
property Img:string read GetImg write SetImg;
property Modulo:string read GetModulo write SetModulo;
property Argumento:string read GetArgumento write SetArgumento;
procedure Suma(a,b:TComplex);
end;
implementation
constructor TComplex.Create;
Begin
inherited Create;
fRe:=0;
fImg:=0;
fModulo:=0;
fArgumento:=0;
existelista:=false;
end;
constructor TComplex.Crear(format:char; input1,input2:string);
Begin
inherited Create;
fRe:=0;
fImg:=0;
fModulo:=0;
fArgumento:=0;
existelista:=false;
Case format of
'R': Begin
If TryStrToFloat(input1,fRe) and TryStrToFloat(input2,fImg) then
GetPolar
else
showmessage('Error: Datos introducidos no válidos');
end;
'P': Begin
If TryStrToFloat(input1,fModulo) and TryStrToFloat(input2,fArgumento) then
GetRectangular
else
showmessage('Error: Datos introducidos no válidos');
end;
end;
end;
function TComplex.GetRe: string;
Begin
Result:=FloatToStr(fRe);
end;
procedure TComplex.SetRe(const AnRe: string);
Begin
fRe:=StrToFloat(AnRe);
end;
procedure TComplex.GetRectangular;
Begin
fRe:=fModulo*cos(fArgumento);
fImg:=fModulo*sin(fArgumento);
end;
procedure TComplex.GetPolar;
Begin
fModulo:=Sqrt(Power(fRe,2)+Power(fImg,2));
If fRe=0 then If fImg=0 then fArgumento:=0
else
If fImg>0 then fArgumento:=Pi/2
else fArgumento:=3*Pi/2
else
If fRe>0 then If fImg=0 then fArgumento:=0
else fArgumento:=arctan(fImg/fRe)
else If fImg>0 then fArgumento:=arctan(fImg/fRe)+Pi
else
If fImg<0 then fArgumento:=arctan(fImg/fRe)-Pi
else fArgumento:=Pi;
end;
procedure TComplex.Suma(a,b:TComplex);
Begin
fRe:=StrToFloat(a.Re)+StrToFloat(b.Re);
fImg:=StrToFloat(a.Img)+StrToFloat(b.Img);
GetPolar;
end;