Ver Mensaje Individual
  #4  
Antiguo 22-03-2010
ioco ioco is offline
Miembro
 
Registrado: ene 2010
Posts: 42
Reputación: 0
ioco Va por buen camino
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;
    { Métodos de acceso }
    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);
    { Métodos de completado por formatos }
    procedure GetRectangular;
    procedure GetPolar;

  public
    { Constructor por defecto Z=0 }
    constructor Create; overload;
    { Constructor de números complejos.
        Dados un formato (P=Polar, R=Rectangular
          y dos parámetros que definan el formato
          crea un número complejo definido completamente
        Valores por defecto Z=0 }
    constructor Crear(format:char; input1,input2:string);

    { Propiedades que definen al objeto }
    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;

    { Métodos públicos }
     //z3.Suma(z1,z2) --> z3=z1+z2
    procedure Suma(a,b:TComplex);

  end;


implementation

  { Constructores }
  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;

  { Métodos de acceso }
  function TComplex.GetRe: string;
    Begin
      Result:=FloatToStr(fRe);
    end;

  procedure TComplex.SetRe(const AnRe: string);
    Begin
      fRe:=StrToFloat(AnRe);
    end;

 { 
  Resumo esta parte para no ocupar tanto post. 
  Igual para:
 
  function TComplex.GetImg: string;
  procedure TComplex.SetImg(const AnImg: string);
  function TComplex.GetModulo:string;
  procedure TComplex.SetModulo(const AnModulo: string);
  function TComplex.GetArgumento:string;
  procedure TComplex.SetArgumento(const AnArgumento: string);
}

  { Métodos de completado por formatos }
  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 // ------------------------------------ Re(z)=0...
         If fImg=0 then // ---------------------------------- ...Img(z)=0
           fArgumento:=0
         else
           If fImg>0 then // -------------------------------- ...Img(z)>0
             fArgumento:=Pi/2
           else // ------------------------------------------ ...Img(z)<0
             fArgumento:=3*Pi/2
      else
        If fRe>0 then // ---------------------------------- Re(z)>0...
          If fImg=0 then // --------------------------------- ...Img(z)=0
            fArgumento:=0
          else  // ------------------------------------------ ...Img(z)>0 , Img(z)<0
            fArgumento:=arctan(fImg/fRe)
        else  //------------------------------------------- Re(z)<0...
          If fImg>0 then // --------------------------------- ...Img(z)>0
            fArgumento:=arctan(fImg/fRe)+Pi
          else
            If fImg<0 then // ------------------------------- ...Img(z)<0
              fArgumento:=arctan(fImg/fRe)-Pi
            else  // ---------------------------------------- ...Img(z)=0
              fArgumento:=Pi;
    end;

  { Métodos públicos}
  procedure TComplex.Suma(a,b:TComplex);
    Begin
      fRe:=StrToFloat(a.Re)+StrToFloat(b.Re);
      fImg:=StrToFloat(a.Img)+StrToFloat(b.Img);
      GetPolar;
    end;

Última edición por ioco fecha: 22-03-2010 a las 15:47:42. Razón: Cambio un poco el código innecesario para que no ocupe tanto
Responder Con Cita