Einzelnen Beitrag anzeigen

Benutzerbild von Matze
Matze
(Co-Admin)

Registriert seit: 7. Jul 2003
Ort: Schwabenländle
14.929 Beiträge
 
Turbo Delphi für Win32
 
#5

Re: Operatoren überschreiben

  Alt 15. Dez 2005, 10:25
Zitat von jim_raynor:
korrekt. Erst ab Delphi 2006
Ok, danke.
Ada, das ja auch auf Pascal basiert, kann das seit 1995, darum habe ich gefragt.

Code:
[b][color=Navy]with[/color][/b] Ada.Integer_Text_IO;

[b][color=green]------------------------------------------------------------------------------
-- PROCEDURE: MultiRationalNumber
-- DESCRIPTION:
--   Main function to add 2 rational numbers
------------------------------------------------------------------------------[/color][/b]
[b][color=Navy]procedure[/color][/b] MultiRationalNumber [b][color=Navy]is[/color][/b]

  [b][color=Navy]type[/color][/b] TRationalNumber [b][color=Navy]is record[/color][/b]
    Numerator: Integer;
    Denominator: Natural;
  [b][color=Navy]end record[/color][/b];
 
[b][color=green] ----------------------------------------------------------------------------
  -- FUNCTION: "*"
  -- DESCRIPTION:
  --   Addition of 2 rational numbers
  -- PARAMETER:
  --   +Number1: 1st rat. number
  --   +Number2: 2nd rat. number
  -- RETURN:
  --   Number1 * Number 2
  -- NOTES: Result is unabridged
  ----------------------------------------------------------------------------[/color][/b]
  [b][color=Navy]function[/color][/b] "*" (Number1, Number2: TRationalNumber) [b][color=Navy]return[/color][/b] TRationalNumber [b][color=Navy]is[/color][/b]
    Result: TRationalNumber;
  [b][color=Navy]begin[/color][/b]
    Result.Numerator := Number1.Numerator * Number2.Numerator;
    Result.Denominator := Number1.Denominator * Number2.Denominator;
   
    [b][color=Navy]return[/color][/b] Result;
  [b][color=Navy]end[/color][/b] "*";
 
  Rat1, Rat2: TRationalNumber;
  NewRationalNumber: TRationalNumber;
[b][color=Navy]begin[/color][/b]
  Rat1.Numerator := 4;
  Rat1.Denominator := 5;
 
  Rat2.Numerator := 7;
  Rat2.Denominator := 12;
 
  NewRationalNumber := Rat1 * Rat2;
 
  Ada.Integer_Text_IO.Put(NewRationalNumber.Numerator);
  Ada.Integer_Text_IO.Put(NewRationalNumber.Denominator);
[b][color=Navy]end[/color][/b];
  Mit Zitat antworten Zitat