AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

LottoTippErstellen

Ein Thema von YXCVBNM1 · begonnen am 1. Sep 2011 · letzter Beitrag vom 2. Sep 2011
Antwort Antwort
Seite 2 von 2     12
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.658 Beiträge
 
Delphi 12 Athens
 
#1

AW: LottoTippErstellen

  Alt 2. Sep 2011, 09:18
Oder etwas verteilter (enthält noch Verbesserungspotential, aber ich wollte auch nicht übertreiben):
Delphi-Quellcode:
type

  TZahlen = array[0..5] of Byte;

  TLottofeld = class
  private
    FZahlen: TZahlen;
  public
    constructor Create;
    property Zahlen: TZahlen read FZahlen;
  end;

  TLottoFelder = array of TLottofeld;

  TLottotipp = class
  private
    FTipps: TLottofelder;
    function GetTipps(Index: integer): TLottofeld;
    function GetTippCount: integer;
  public
    constructor Create(Anzahl: Cardinal);
    destructor Destroy; override;
    property Tipps[Index: integer]: TLottofeld read GetTipps; default;
    property TippCount: integer read GetTippCount;
  end;

{ TLottofeld }

constructor TLottofeld.Create;
var
  Liste: TList;
  i, Index: integer;

  procedure Swap(var a, b: Byte);
  var
    tmp: Byte;
  begin
    tmp := a;
    a := b;
    b := tmp;
  end;

  procedure Bubblesort;
  var
    Done: Boolean;
    j, LastPos: integer;
  begin
    LastPos := High(FZahlen);
    repeat
      Done := true;
      for j := Low(FZahlen) to LastPos - 1 do
        if FZahlen[j] > FZahlen[j + 1] then
          begin
            Swap(FZahlen[j], FZahlen[j + 1]);
            Done := false;
          end;
      dec(LastPos);
    until Done;
  end;

begin
  Liste := TList.Create;
  try
    for i := 1 to 49 do
      Liste.Add(Pointer(i));
    for i := Low(FZahlen) to High(FZahlen) do
      begin
        Index := Random(Liste.Count);
        FZahlen[i] := integer(Liste[Index]);
        Liste.Delete(Index);
      end;
    Bubblesort;
  finally
    Liste.Free;
  end;
end;

{ TLottotipp }

constructor TLottotipp.Create(Anzahl: Cardinal);
var
  i: integer;
begin
  SetLength(FTipps, Anzahl);
  for i := 0 to Anzahl - 1 do
    FTipps[i] := TLottofeld.Create;
end;

destructor TLottotipp.Destroy;
var
  i: integer;
begin
  for i := Low(FTipps) to High(FTipps) do
    FTipps[i].Free;
  SetLength(FTipps, 0);
  inherited;
end;

function TLottotipp.GetTippCount: integer;
begin
  Result := Length(FTipps);
end;

function TLottotipp.GetTipps(Index: integer): TLottofeld;
begin
  Result := FTipps[Index];
end;
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:58 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz