).varI know that I can capture the ammount of times each character appears in the memo box, as I have another box that displays the hits of each character (that last part of the code) But from there. Im kind of in a fix.
Form1: TForm1;
alpha:array [1..27]of integer; //array de 1 ? 26 pour les lettres A-Z
textlength:array [1..26]of string; //memo1 doit etre egal a 26!!!
count,rank,length:integer;
completed:boolean;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.Clear;
memo2.lines.clear;
memo3.lines.clear;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
form1.Close;
end;
procedure Countchars;
begin
for count:= 1 to 26 do
begin
if (textlength[count] = #065) or (textlength[count] = #097) then
alpha[1]:=alpha[1]+1;
if (textlength[count] = #066) or (textlength[count] = #098) then
alpha[2]:=alpha[2]+1;
if (textlength[count] = #067) or (textlength[count] = #099) then
alpha[3]:=alpha[3]+1;
if (textlength[count] = #068) or (textlength[count] = #100) then
alpha[4]:=alpha[4]+1;
if (textlength[count] = #069) or (textlength[count] = #101) then
alpha[5]:=alpha[5]+1;
if (textlength[count] = #070) or (textlength[count] = #102) then
alpha[6]:=alpha[6]+1;
if (textlength[count] = #071) or (textlength[count] = #103) then
alpha[7]:=alpha[7]+1;
if (textlength[count] = #072) or (textlength[count] = #104) then
alpha[8]:=alpha[8]+1;
if (textlength[count] = #073) or (textlength[count] = #105) then
alpha[9]:=alpha[9]+1;
if (textlength[count] = #074) or (textlength[count] = #106) then
alpha[10]:=alpha[10]+1;
if (textlength[count] = #075) or (textlength[count] = #107) then
alpha[11]:=alpha[11]+1;
if (textlength[count] = #076) or (textlength[count] = #108) then
alpha[12]:=alpha[12]+1;
if (textlength[count] = #077) or (textlength[count] = #109) then
alpha[13]:=alpha[13]+1;
if (textlength[count] = #078) or (textlength[count] = #110) then
alpha[14]:=alpha[14]+1;
if (textlength[count] = #079) or (textlength[count] = #111) then
alpha[15]:=alpha[15]+1;
if (textlength[count] = #080) or (textlength[count] = #112) then
alpha[16]:=alpha[16]+1;
if (textlength[count] = #081) or (textlength[count] = #113) then
alpha[17]:=alpha[17]+1;
if (textlength[count] = #082) or (textlength[count] = #114) then
alpha[18]:=alpha[18]+1;
if (textlength[count] = #083) or (textlength[count] = #115) then
alpha[19]:=alpha[19]+1;
if (textlength[count] = #084) or (textlength[count] = #116) then
alpha[20]:=alpha[20]+1;
if (textlength[count] = #085) or (textlength[count] = #117) then
alpha[21]:=alpha[21]+1;
if (textlength[count] = #086) or (textlength[count] = #118) then
alpha[22]:=alpha[22]+1;
if (textlength[count] = #087) or (textlength[count] = #119) then
alpha[23]:=alpha[23]+1;
if (textlength[count] = #088) or (textlength[count] = #120) then
alpha[24]:=alpha[24]+1;
if (textlength[count] = #089) or (textlength[count] = #121) then
alpha[25]:=alpha[25]+1;
if (textlength[count] = #090) or (textlength[count] = #122) then
alpha[26]:=alpha[26]+1;
{Maintenant, tous les lettres son classifi?es dans l'array. Il
faut donc les trier en ordre d?croissant.}
end;
end;
procedure Sort;
var
trie:boolean;
aux,chars:integer;
begin
repeat
trie:=true;
for rank:=1 to 25 do begin
if alpha[rank] < alpha[rank+1] then
begin
aux:=alpha[rank];
alpha[rank]:=alpha[rank+1];
alpha[rank+1]:=aux;
trie:=false;
end;
end;
until trie=true;
//Is the triage really needed?
//WHAT IS WRONG WITH THE 'CASE' INSTRUCTION!?!?!
for count:= 1 to 26 do begin
case alpha[count] of
1: textlength[count]:='E'; //substitue la lettre la plus commune avec la lettre E
2: textlength[count]:='T'; //substitue la lettre la deuxieme plus commune avec la lettre T
3: textlength[count]:='I'; //et ainsi de suite
4: textlength[count]:='A';
5: textlength[count]:='O';
6: textlength[count]:='N';
7: textlength[count]:='S';
8: textlength[count]:='R';
9: textlength[count]:='H';
10: textlength[count]:='C';
11: textlength[count]:='L';
12: textlength[count]:='D';
13: textlength[count]:='P';
14: textlength[count]:='Y';
15: textlength[count]:='U';
16: textlength[count]:='M';
17: textlength[count]:='F';
18: textlength[count]:='B';
19: textlength[count]:='G';
20: textlength[count]:='W';
21: textlength[count]:='V';
22: textlength[count]:='K';
23: textlength[count]:='X';
24: textlength[count]:='Q';
25: textlength[count]:='Z';
26: textlength[count]:='J';
end;
{il faut maintenant reprendre le texte originale
et y substituer les lettres}
end;
for chars:= 1 to 26 do begin
form1.memo2.text:=(form1.memo2.Text+textlength[chars]);
end;
completed:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
begin
completed:=false;
if form1.memo1.Text=('') then showmessage('Enter a message to run the frequency check')
else begin
alpha[1]:=0;
alpha[2]:=0;
alpha[3]:=0;
alpha[4]:=0;
alpha[5]:=0;
alpha[6]:=0;
alpha[7]:=0;
alpha[8]:=0;
alpha[9]:=0;
alpha[10]:=0;
alpha[11]:=0;
alpha[12]:=0;
alpha[13]:=0;
alpha[14]:=0;
alpha[15]:=0;
alpha[16]:=0;
alpha[17]:=0;
alpha[18]:=0;
alpha[19]:=0;
alpha[20]:=0;
alpha[21]:=0;
alpha[22]:=0;
alpha[23]:=0;
alpha[24]:=0;
alpha[25]:=0;
alpha[26]:=0;
memo2.Lines.Clear;
memo3.lines.Clear;
length:=memo1.GetTextLen;
for i:= 1 to 26 do begin
textlength[i] :=form1.memo1.Text[i];
end;
Countchars;
memo3.lines.add('string contains ' +Inttostr(length)+ ' characters');
memo3.lines.add('================================');
memo3.Lines.add('Frequency of letter A: '+Inttostr(alpha[1]));
memo3.Lines.add('Frequency of letter B: '+Inttostr(alpha[2]));
memo3.Lines.add('Frequency of letter C: '+Inttostr(alpha[3]));
memo3.Lines.add('Frequency of letter D: '+Inttostr(alpha[4]));
memo3.Lines.add('Frequency of letter E: '+Inttostr(alpha[5]));
memo3.Lines.add('Frequency of letter F: '+Inttostr(alpha[6]));
memo3.Lines.add('Frequency of letter G: '+Inttostr(alpha[7]));
memo3.Lines.add('Frequency of letter H: '+Inttostr(alpha[8]));
memo3.Lines.add('Frequency of letter I: '+Inttostr(alpha[9]));
memo3.Lines.add('Frequency of letter J: '+Inttostr(alpha[10]));
memo3.Lines.add('Frequency of letter K: '+Inttostr(alpha[11]));
memo3.Lines.add('Frequency of letter L: '+Inttostr(alpha[12]));
memo3.Lines.add('Frequency of letter M: '+Inttostr(alpha[13]));
memo3.Lines.add('Frequency of letter N: '+Inttostr(alpha[14]));
memo3.Lines.add('Frequency of letter O: '+Inttostr(alpha[15]));
memo3.Lines.add('Frequency of letter P: '+Inttostr(alpha[16]));
memo3.Lines.add('Frequency of letter Q: '+Inttostr(alpha[17]));
memo3.Lines.add('Frequency of letter R: '+Inttostr(alpha[18]));
memo3.Lines.add('Frequency of letter S: '+Inttostr(alpha[19]));
memo3.Lines.add('Frequency of letter T: '+Inttostr(alpha[20]));
memo3.Lines.add('Frequency of letter U: '+Inttostr(alpha[21]));
memo3.Lines.add('Frequency of letter V: '+Inttostr(alpha[22]));
memo3.Lines.add('Frequency of letter W: '+Inttostr(alpha[23]));
memo3.Lines.add('Frequency of letter X: '+Inttostr(alpha[24]));
memo3.Lines.add('Frequency of letter Y: '+Inttostr(alpha[25]));
memo3.Lines.add('Frequency of letter Z: '+Inttostr(alpha[26]));
Sort;
if completed=true then Showmessage('Frequency check complete');
end;
end;
end.
WC, all it does is implement what I was trying to explain before. Have another read of that.Yes.
Is
this for an asignment or something? If so, didn't they give you some
idea as to how you go about writing a program like this?

I've never heard of a hash table before.Here:
I would try some basic programming in Java had I had an editor. But even on p2p networks I cant find it.
As for the advantages of languages, I didnt know that. And yes, I'll admit my knowledge in programming is very limited.
Im just scratching my butt on this one because it seems right (to me) but I just get some really weird outputs.