unit Vraag3_U;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ExtCtrls, ComCtrls;

type
  TfrmVraag3 = class(TForm)
    redAfvoer: TRichEdit;
    pnlOpsies: TPanel;
    btnA: TButton;
    btnB: TButton;
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure btnAClick(Sender: TObject);
    procedure btnBClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmVraag3: TfrmVraag3;
  arrInfo  : array[1..12] of String[30];
implementation



{$R *.dfm}

procedure TfrmVraag3.FormCreate(Sender: TObject);
begin
  arrInfo[1]:= 'HDRDBRHRHDdRHHDDrhbRR';
  arrInfo[2]:= 'RrBHDrBrRHBBDRHDdBRRhb';
  arrInfo[3]:= 'BBRRRbDBRrBBHHRBBB';
  arrInfo[4]:= 'RBBRBRdBRDBDRRRBbRRRRbBDHHH';
  arrInfo[5]:= 'RHDBBBHRBB';
  arrInfo[6]:= 'RbrBrBDdRrBb';
  arrInfo[7]:= 'bRRbhbdB';
  arrInfo[8]:= 'hbB';
  arrInfo[9]:= 'BHRrB';
  arrInfo[10]:= 'HhbrbBHhRrdrbBDRRRBB';
  arrInfo[11]:= 'BBBbrrRRdrHRBbBRdDBRBDRrBBDRdB';
  arrInfo[12]:= 'BRBrHRBBRrhHHrrRBDbBDbRRrRRBBDRBDDRHhHD';

  redAfvoer.Paragraph.TabCount := 3;
  redAfvoer.Paragraph.Tab[0] := 1;
  redAfvoer.Paragraph.Tab[1] := 30;
  redAfvoer.Paragraph.Tab[2] := 300;

end;

procedure TfrmVraag3.btnAClick(Sender: TObject);
var
  K, M, iTel, iTotaleRowe, iTotaleMisdaad  :integer;
  sNuweString, sMaand    :String;
  rPersentasie :real;
begin
  redAfvoer.Lines.Add('Maande' + #9 + 'Statistiek' + #9 + 'Gewapende roof');
  iTotaleRowe := 0;
  iTotaleMisdaad := 0;
  for K := 1 to 12 do
    begin
      iTel := 0;
      sNuweString := IntToStr(K)+ #9;
      for M := 1 to length(arrInfo[K]) do
        begin
        case  upcase(arrInfo[K][M]) of
        'B', 'D', 'H' : sNuweString := sNuweString + lowercase(arrInfo[K][M]);
        'R':begin
              sNuweString := sNuweString + upcase( arrInfo[K][M]);
              iTel := iTel + 1;
            end;
        end;


        end;
        iTotaleRowe := iTotaleRowe + iTel;
        iTotaleMisdaad := iTotaleMisdaad + length(arrInfo[K]);
        sNuweString :=  #9 + sNuweString + #9 + intToStr(iTel);
        redAfvoer.Lines.Add(sNuweString);
     end;
     rPersentasie := iTotaleRowe / iTotaleMisdaad * 100;
     redAfvoer.Lines.Add(' ');
     redAfvoer.Lines.Add('Die persentasie gewapende rowe ' + floatToStrF(rPersentasie, ffFixed, 0, 1));
end;

procedure TfrmVraag3.btnBClick(Sender: TObject);
var
  iLength, K, iCount, iFound  :integer;
  sString :string;
  bFound :boolean;
  sCrime :string;
begin
  sCrime := InputBox('Crimes', 'Which crime (b/d/h/r)?', '');
  iLength := 0;
  for K := 1 to 12 do
    begin
      if length(arrInfo[K]) > iLength then
        iLength := length(arrInfo[K]);
    end;
  sString := '';
  for K := 1 to iLength do
    sString := sString + sCrime[1];
  bFound := false;
  while (bFound = false)and (length(sString)>= 2) do
  begin
   iCount := 1;
   while (bFound = false) and (iCount <=12) do
   begin
    iFound := pos(Uppercase(sString), uppercase(arrInfo[iCount]));
    if (iFound > 0) then
      bFound := true;

     iCount := iCount + 1;
   end;   // inner while
  if (bFound = true) then
    begin
      redAfvoer.Lines.Add(' ');
      redAfvoer.Lines.Add('Crime: '+ sCrime);
      redAfvoer.Lines.Add('The month with the most consecutive occurences: ' + intToStr(iCount-1));
      redAfvoer.Lines.Add('The number of consecutive occurences during this month: ' +   IntToStr(length(sString)));
    end;
    sString := copy(sString, 1, length(sString)- 1);

end;  // outer while


end;

end.
