Need some help with programming

Need some help with programming

Re: Need some help with programming Posted by Wild Card on Fri Dec 17th 2004 at 12:21am
Wild Card
2321 posts
Posted 2004-12-17 12:21am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
This is using Delphi by the way, but I still figure you guys could help out even if you dont know the language.

Ok, I have a memo box (a giant box to type in a lot of text, like a form) And I made an array from 1 to 26. Since there are only 26 characters in the alphabet.

What I need is to assign each array a character, A to Z. So [1] is A, [2] is B, [3] is C, and so on. And if there are 3 a's in the memo, then [1] will equal 3. If that makes sence to you guys.

After that, once it's got all the numbers of characters, it will sort them in assending order. So say the memo contains abbbcccccddddee

then

[1]=1
[2]=3
[3]=5
[4]=4
[5]=2

And then it would sort them in order

[1]=1
[5]=2
[2]=3
[4]=4
[3]=5

Anyone know how I might go about doing that?

Thanks
Re: Need some help with programming Posted by scary_jeff on Fri Dec 17th 2004 at 1:08am
scary_jeff
1614 posts
Posted 2004-12-17 1:08am
1614 posts 191 snarkmarks Registered: Aug 22nd 2001
Well I don't think you can sort them like that. If something array offset 0 means 'number of As', then you can't move that somewhere else as far as I know. The other bit is easy, just set up your array of character totals 'array[26]' go through the string one character at a time, subtract #30 (or whatever the hex offset in the ascii chart for 'a' is), let this number equal say 'var1', then do array[var1]++. Obviously you would have to go through the string converting everything to either upper or lower case (whatever you choose, either add or subtract from each char the hex number that is the difference between A and a in the ascii chart), and set some other clause for if the character isn't a letter.
Re: Need some help with programming Posted by Wild Card on Fri Dec 17th 2004 at 1:20am
Wild Card
2321 posts
Posted 2004-12-17 1:20am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
thanks for the reply jeff.

I dont really care about uppercase or lowercase really. I'd convert it all to lower case.

Here is what I've goten so far. I have tryed it yet, its not finished.

Working off 2 array (and damn is it ever confusing) and a few variables.

1 array to keep score of the ammount of times a character appears, the other array for counting every character and passing them off to the first array for hit storage (see I told you it was confusing :biggrin: )

<DIV class=quote>
<DIV class=quotetitle>? quote:</DIV>
<DIV class=quotetext>
var
Form1: TForm1;
text:string; //I put the memo text in this string
alpha:array [1..26]of integer; //first array for keeping hit count on characters

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.Clear;
memo2.lines.clear;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
form1.Close;
end;

procedure Sort; //procedure that gets called
var
i: integer;
textlength:array [1..10000]of string; //counts the ammount of characters
begin
if (textlength[i] = #065) then //if the character is #065 (a) then it adds +1 to the first array
alpha[1]:=alpha[1]+1;
if (textlength[i] = #066) then
alpha[2]:=alpha[2]+1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
count:Integer;
begin
text:=memo1.Text; //gives the text string variable the value of the memo text
memo2.text:=(text);
for i:= 1 to count do begin
alpha[i]:=(memo1.Text[count])
end;
Sort; //calls the sort procedure
end;

end.

</DIV></DIV>
[EDIT] When I run the program, I get pointed to the second last end (the one in red) and am given this error: Incompatible types: 'Integer' and 'Char'
Re: Need some help with programming Posted by scary_jeff on Fri Dec 17th 2004 at 1:37am
scary_jeff
1614 posts
Posted 2004-12-17 1:37am
1614 posts 191 snarkmarks Registered: Aug 22nd 2001
You don't want to have a different if statement for every letter. instead of what you have there, get rid of the if statement in the sort procedure. Instead (this won't work, I have no idea about delphi), create a second variable (say 'j') where you create i, then replace

if (textlength[i] = #065)
alpha[1]:=alpha[1]+1;
if (textlength[i] = #066) then
alpha[2]:=alpha[2]+1;
if (textlength[i] = #067) then
alpha[3]:=al... bla bla etc

with

j:=texlength[i]-#065
alpha[j]:=alpha[j]+1;

Probably some type mismatch or something, but that's the general idea I was thinking of. Seems a lot neater than having the same 2 lines 26 times in a row.
Re: Need some help with programming Posted by Wild Card on Fri Dec 17th 2004 at 1:45am
Wild Card
2321 posts
Posted 2004-12-17 1:45am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
How would I go about changing the ASCII character value? I havent tryed it though.

Here's what I've got. Still getting that error though :sad:

<DIV class=quote>
<DIV class=quotetitle>? quote:</DIV>
<DIV class=quotetext>unit Crypt_App;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Memo1: TMemo;
Button1: TButton;
BitBtn1: TBitBtn;
Memo2: TMemo;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
text:string;
alpha:array [1..26]of integer; //array de 1 ? 26 pour les lettres A-Z

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.Clear;
memo2.lines.clear;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
form1.Close;
end;

procedure Sort;
var
i: integer;
textlength:array [1..10000]of string; //compte le nombre de lettres dans le memo1
begin
if (textlength[i] = #065) then //si la lettre est #065 (a) ajoute +1 au array alpha[1]
alpha[1]:=alpha[1]+1;
if (textlength[i] = #066) then //si la lettre est #066 (b) ajoute +2 au array alpha[2]
alpha[2]:=alpha[2]+1;
if (textlength[i] = #067) then
alpha[3]:=alpha[3]+1;
if (textlength[i] = #068) then
alpha[4]:=alpha[4]+1;
if (textlength[i] = #069) then
alpha[5]:=alpha[5]+1;
if (textlength[i] = #070) then
alpha[6]:=alpha[6]+1;
if (textlength[i] = #071) then
alpha[7]:=alpha[7]+1;
if (textlength[i] = #072) then
alpha[8]:=alpha[8]+1;
if (textlength[i] = #073) then
alpha[9]:=alpha[9]+1;
if (textlength[i] = #074) then
alpha[10]:=alpha[10]+1;
if (textlength[i] = #075) then
alpha[11]:=alpha[11]+1;
if (textlength[i] = #076) then
alpha[12]:=alpha[12]+1;
if (textlength[i] = #077) then
alpha[13]:=alpha[13]+1;
if (textlength[i] = #078) then
alpha[14]:=alpha[14]+1;
if (textlength[i] = #079) then
alpha[15]:=alpha[15]+1;
if (textlength[i] = #080) then
alpha[16]:=alpha[16]+1;
if (textlength[i] = #081) then
alpha[17]:=alpha[17]+1;
if (textlength[i] = #082) then
alpha[18]:=alpha[18]+1;
if (textlength[i] = #083) then
alpha[19]:=alpha[19]+1;
if (textlength[i] = #084) then
alpha[20]:=alpha[20]+1;
if (textlength[i] = #085) then
alpha[21]:=alpha[21]+1;
if (textlength[i] = #086) then
alpha[22]:=alpha[22]+1;
if (textlength[i] = #087) then
alpha[23]:=alpha[23]+1;
if (textlength[i] = #088) then
alpha[24]:=alpha[24]+1;
if (textlength[i] = #089) then
alpha[25]:=alpha[25]+1;
if (textlength[i] = #090) then
alpha[26]:=alpha[26]+1;

end;

procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
count:integer;
begin
text:=memo1.Text; //met le contenu de memo1 dans la variable string text
memo2.text:=(text); //le contenu de memo2 est la variable string text
for i:= 1 to 10000 do begin
alpha[i]:=(memo1.Text[count])
end;
Sort;
end;

end.

</DIV></DIV>
[EDIT] narrowed down my error to this line (in red)

By the way Lep, I absolutly hate this new quotes thing you did, its so hard going back and editing it since its got a weird scrolling feature.

Thanks for the help Jeff :smile:
Re: Need some help with programming Posted by Foxpup on Fri Dec 17th 2004 at 2:26am
Foxpup
380 posts
Posted 2004-12-17 2:26am
Foxpup
member
380 posts 38 snarkmarks Registered: Nov 26th 2004 Occupation: Student Location: the Land of Oz
I'm no good at Delphi, so I'll just mix Object Pascal and Pseudocode and hopefully you'll get the idea! :smile:
Try something like:

for character := 1 to 26
begin
if alpha[character] &amp;gt; 0 then //if it's a non zero number...
begin
for x := 1 to alpha[character] //...print that character that many times
print chr(character + <whatever ascii code for A - 1 is>);
next x;
end;
else begin end; end if; end; //else do nothing
next character;
Re: Need some help with programming Posted by Wild Card on Fri Dec 17th 2004 at 3:02am
Wild Card
2321 posts
Posted 2004-12-17 3:02am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
Sorry I dont really understand that. Like character, is that a variable or an array?

And whats &gt and &lt
Re: Need some help with programming Posted by Foxpup on Fri Dec 17th 2004 at 3:10am
Foxpup
380 posts
Posted 2004-12-17 3:10am
Foxpup
member
380 posts 38 snarkmarks Registered: Nov 26th 2004 Occupation: Student Location: the Land of Oz
Variable of type BYTE ie 0..255
or int, but byte uses half as much RAM

Oh, and < and > were originally arrows, but it screwed up somehow...

WHOOPS!!! for "index", read "character"...
Re: Need some help with programming Posted by Crono on Sat Dec 18th 2004 at 9:32pm
Crono
6628 posts
Posted 2004-12-18 9:32pm
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
Jeff, prefix unless you specifically
want postfix (just get used to it already!).

WC, honestly, I'd
suggest using a different data structure to do this. Arrays aren't
the greatest thing to work with when pertaining to individual
elements (without combination of other structures).

Foxup, you
don't use memory sizes in pseudo code. The entire point of pseudo
code is to understand what you're doing more; you kind of defeated
that :smile: .
That stuff you wrote isn't pseudo code, it's pretty close
to Ada (if I remember properly) and some other scripting languages
... coughMaplecough (And Delphi apparently
:wtf: ).

WC, your code only checks 1 element in the entire
array, since you never increment i (using the much more memory
friendly method of prefix).

Just to clean up your code (and
not have someone telling you how to completely solve your problem,
because you don't learn that way)

you can tackle this with a
loop. Especially the way you've been writing the function.

It'd
be something like

var i = 1;
var j = 65

for (i = 1;
i < 27; ++i)
{
if (textlength[i] = j)

{
alpha[i] :=
++alpha[i];
}

++j;
}

adapt it to Delphi and it'll save you a crap load of
time.

With that line you highlighted, what are you trying to
do exactly. Because it looks like it'll go through you overly large
10,000 element array and assign each one to a non-valued integer
(unless Delphi has a default assigning value)
If you want it to be
different value and not the same you need to do something like
increment 'count' (assigning a value to it wouldn't hurt either).

I
suppose just try it out.
Re: Need some help with programming Posted by Wild Card on Sun Dec 19th 2004 at 3:41am
Wild Card
2321 posts
Posted 2004-12-19 3:41am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
I'll take your input into consideration Crono :smile: Mind you Im still fairly rusty with my programming. I've had to look at examples of codes (for the sorting) and another on the arrays to built mine. Not that the other code was really relevant, but thats how I work.

Anyways, here's what I have now:
var
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.
I 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.

The alpha array has 27 values. I had it on 26 values before but it would give a random number for the letter 'Z' (I think it was 1248000 something like that) so I put it to 27 and it works fine. Although I never once use the 27th slot.

The textlength array counts the characters in the memobox. I had it assigned 10 000 values so that I wouldnt be limited to the ammount of text I could enter, however I discovered that the ammount of text has to EXACTLY match the array size. If there is too little text for the array, I get random extra characters counted that dont exist. To much text and the excess is ignored.

But yea, Im stumped on this one. Been playing around with my variables and nothing seems to help.
Re: Need some help with programming Posted by Crono on Sun Dec 19th 2004 at 5:17am
Crono
6628 posts
Posted 2004-12-19 5:17am
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
Does Delphi start counting arrays at 1
instead of 0?

That extra character could be a null character
or newline or something like that which is usually cut off if there
isn't enough room (not a null character, obviously it needs to know
where to end).

To be honest, the code your putting up is
pretty foreign. Not that it's overly complex or anything, it's not
complex enough for me to understand in some respects (I have this
issue from time to time in maple. I'm too used to C/C++). It seems
like you're having Delphi issues and not programming issues. I
suggest reading up on exactly how the data types and structures
you're using work.

Not to mention it appears that your
program is not doing what you said you wanted it to do in your
original post.
Re: Need some help with programming Posted by Wild Card on Sun Dec 19th 2004 at 8:30pm
Wild Card
2321 posts
Posted 2004-12-19 8:30pm
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
Arrays start at whatever number I start them at. So in this case, 1..27 will be 1 to 27, including.

Just looking at your piece of code:

var i = 1;
var j = 65

for (i = 1; i < 27; ++i)
{
if (textlength[i] = j)
{
alpha[i] := ++alpha[i];
}

++j;
}

I dont get why i = 1 and j = 65. Im assuming they are integer variables, but I dont know why you chose 1 and 65 values. Little confused as to what it's supposed to do.
Re: Need some help with programming Posted by scary_jeff on Sun Dec 19th 2004 at 9:10pm
scary_jeff
1614 posts
Posted 2004-12-19 9:10pm
1614 posts 191 snarkmarks Registered: Aug 22nd 2001
WC, all it does is implement what I was trying to explain before. Have another read of that.

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?
Re: Need some help with programming Posted by Crono on Sun Dec 19th 2004 at 9:28pm
Crono
6628 posts
Posted 2004-12-19 9:28pm
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
WC, all it does is implement what I was trying to explain before. Have another read of that.

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?
Yes.

They are integers. You
started repeating the values over and over and over again when a loop
is far more efficient (for you).

You started counting from 1
to 26, thus the loop counter is set to 1 and it will stop looping if
i is more then or equal to 27 (meaning it will only loop 26
times).
The other value is the ASCII value of the characters that
you went through comparing. You started at 65 and counted to 90, you
could just as easily loop that part as well incrementing with each
iteration. It doesn't matter that you added new code, those parts can
be incremented with a integer variable as well.

Like I said,
I'm not sure what the program is doing exactly, since you just have
the array written over at the end :confused:

Not to mention I
would rather not lay out an answer if this is an assignment for
class, as Jeff questioned.
Re: Need some help with programming Posted by Wild Card on Sun Dec 19th 2004 at 9:43pm
Wild Card
2321 posts
Posted 2004-12-19 9:43pm
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
No Jeff, this isnt an assignment. I did 2 years in high school with Delphi, and then did 1 year of Java. Now Im continuing on with Delphi on my own time, sometimes going back to my programming teacher, however he is not the best at this. Me and him had to work together on this one and we couldnt solve it. (He helped me confirm my code was working)

And internet or book help is really really limited with Delphi. And Im not as lame as to seek help on the internet. Im not like that.

Ok, exactly what the program is supposed to be doing. Ok, we all know the most basic form of encryption is to change the letter of the alphabet. Such as this for example: If I wrote HELLO and wanted to incrypt it, then perhaps I would type in VNKKW

Simple encryption like this can be broken with character frequency. Used best for long texts however. The most common letter is 'E' followed be 'T' and so on.

My program is supposed to take that encrypted text and decrypt it. The way I think of doing it is having it count all the characters in the memo (the textlength array) and then it will count the identical letters (the alpha array) Then sort that array and change the letters.

If that makes sence. And again, this isnt for a class assignment. I took Delphi programming 2 years ago.
Re: Need some help with programming Posted by Crono on Sun Dec 19th 2004 at 10:56pm
Crono
6628 posts
Posted 2004-12-19 10:56pm
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
Oh, dude. There are algorithms for
encryption. And yes, that is very simple encryption :smile:

I'm not
entirely sure why you chose Delphi over Java though. Java is by far
a more powerful language.

Well, if you wanted to use arrays for this you
could use a variation of pointer arithmetic and such to get a desired
encoding effect. Not sure how you do that in Delphi though.

If you're creating this to have
messages encoded or decoded: a MUCH easier way would be to do it by
character and just use an equation on each ASCII value to encode or
decode. You can keep the strings in arrays if you like. But what
you're doing still doesn't make sense, it's just ridiculously
inefficient.

Also, don't be discouraged, encryption of any kind isn't a really
easy task, especially if the language you use isn't really made for it.
Re: Need some help with programming Posted by Wild Card on Mon Dec 20th 2004 at 12:36am
Wild Card
2321 posts
Posted 2004-12-20 12:36am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
I chose Delphi since it is the first language I learned (if you dont count BASIC which I self tough myself many years back) and I cannot do things as complex as this in Java. Nor do I have a Java editor at home.

I realise now that my use of arrays make the program much more complex and complicated than it auth to be. I guess at the time I had not considered the use of a loop. I will try that now.

The goal of the program at the moment is simply decryption. Perhaps later I will modify it for encryption (which would be almost identical except backwards).

Another thing I have come to realise is that if I use arrays to capture the length of the text, the length of the text and the size of the array must be identical. (IE 100 character text for a 100value array) And I cannot add an integer to the array to make it 1 (or 0 :razz: ) to integer value.

I also dont care about wether the letter is uppercase or lowercase, my program would treat them as identical. Which is why I have it set to capture both $065 and $097 for the character 'A'

I will try the loop. Although I am slightly unsure how to proceed on that one. Mind you I was stuck on the arrays too :rolleyes:

We'll see.
Re: Need some help with programming Posted by Orpheus on Mon Dec 20th 2004 at 12:39am
Orpheus
13860 posts
Posted 2004-12-20 12:39am
Orpheus
member
13860 posts 2024 snarkmarks Registered: Aug 26th 2001 Occupation: Long Haul Trucking Location: Long Oklahoma - USA
doesn't it bother you in the least that i do not understand a single bit of this entire thread?

have some mercy on an old fella.. at least post something i can grasp.. perhaps you know of a store that has a sale on some depends?
Re: Need some help with programming Posted by Wild Card on Mon Dec 20th 2004 at 12:47am
Wild Card
2321 posts
Posted 2004-12-20 12:47am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
Can I comfort you by saying I do not fully understand it all myself? :biggrin:
Re: Need some help with programming Posted by SaintGreg on Mon Dec 20th 2004 at 4:22am
SaintGreg
212 posts
Posted 2004-12-20 4:22am
212 posts 51 snarkmarks Registered: Dec 3rd 2004
<h1><center>
<div style="text-align: left;">note: i didn't write this, but it fits this thread like a glove.

</div>

WRITE IN C</center></h1>

<h3><center>(sung to The Beatles "Let it Be")</center></h3>

<center>When I find my code in tons of trouble,

Friends and colleagues come to me,

Speaking words of wisdom:

"Write in C."</center>

<center>As the deadline fast approaches,

And bugs are all that I can see,

Somewhere, someone whispers"

"Write in C."</center>

<center>Write in C, write in C,

Write in C, write in C.

LISP is dead and buried,

Write in C.</center>

<center>I used to write a lot of FORTRAN,

for science it worked flawlessly.

Try using it for graphics!

Write in C.</center>

<center>If you've just spent nearly 30 hours

Debugging some assembly,

Soon you will be glad to

Write in C.</center>

<center>Write in C, write in C,

Write In C, yeah, write in C.

Only wimps use BASIC.

Write in C.</center>

<center>Write in C, write in C,

Write in C, oh, write in C.

Pascal won't quite cut it.

Write in C.</center>

<center>Guitar Solo</center>

<center>Write in C, write in C,

Write in C, yeah, write in C.

Don't even mention COBOL.

Write in C.</center>

<center>And when the screen is fuzzy,

And the editor is bugging me.

I'm sick of ones and zeroes.

Write in C.</center>

<center>A thousand people people swear that T.P.

Seven is the one for me.

I hate the word PROCEDURE,

Write in C.</center>

<center>Write in C, write in C,

Write in C, yeah, write in C.

PL1 is 80's,

Write in C.</center>

<center>Write in C, write in C,

Write in C, yeah, write in C.

The government loves ADA,

Write in C.</center>
Re: Need some help with programming Posted by Wild Card on Mon Dec 20th 2004 at 4:57am
Wild Card
2321 posts
Posted 2004-12-20 4:57am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
ait well I think I've failed. The only way I can think of doing it is with the damn arrays. I've tryed thinking of how to do it with a loop but I cant see how I would do to capture the characters in the text without using 2 arrays. Or a heck of a lot of variables.
Re: Need some help with programming Posted by Foxpup on Mon Dec 20th 2004 at 4:58am
Foxpup
380 posts
Posted 2004-12-20 4:58am
Foxpup
member
380 posts 38 snarkmarks Registered: Nov 26th 2004 Occupation: Student Location: the Land of Oz
That's what an array is: a heck of a lot of varaiables. :smile:
Re: Need some help with programming Posted by Crono on Mon Dec 20th 2004 at 5:04am
Crono
6628 posts
Posted 2004-12-20 5:04am
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
Case should really never matter almost
every language has some library with a pre-written function to change
case. C++ has tolower and toupper. Easy.

I'd honestly suggest
using Java though, basically what I wrote could be slapped into Java
or C++ (they have the same syntax).

Ew, Fortran. Can you hear
it? All the programmers going insane when they get a compile error
AFTER EIGHT HOURS OF COMPILING! ... on the older versions that
is.

WC, I'd just suggest looking at some other data structures
then JUST an array. I mean, a hash table would work pretty well I'd
imagine, but again, I doubt Delphi has the ability.

Also, for
Java editing, if you HAVE to use a suite (which I actually suggest)
use Eclipse or something as such. It's pretty damn nice. They're
releasing some C and C++ plug-ins too.

I just don't think you
know enough to really solve this problem, and your choice for
language is terrible. It's just going to make things harder. You're
SUPPOSE to choose a suitable language for your problem and what you'd
like to achieve (speed = C, Super Speed = Asm, polymorphism = C++,
pseudo-OOP = Java, etc.)

[EDIT]

WC, I didn't say "use a loop instead of an array". Use them both.

(An array is much more then just a bunch of variables of the same type)

Maybe you should read up on Delphi arrays and then come back to this thread.
Re: Need some help with programming Posted by Wild Card on Mon Dec 20th 2004 at 5:15am
Wild Card
2321 posts
Posted 2004-12-20 5:15am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
I've never heard of a hash table before.

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.
Re: Need some help with programming Posted by Crono on Mon Dec 20th 2004 at 5:22am
Crono
6628 posts
Posted 2004-12-20 5:22am
Crono
super admin
6628 posts 700 snarkmarks Registered: Dec 19th 2003 Location: Oregon, USA
I've never heard of a hash table before.

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.
Here:

http://eclipse.org/downloads/index.php

and Java:

https://jsecom16.sun.com/ECom/EComActionServlet;jsessionid=F6C4998344116D993C2C42351CAD9405

This is the 1.4 SDK, I'm not sure if you need the full SDK or just the JRE or whatever it is.

A hash table is a semi-complex data structure which combines an array
and linear linked lists (you can also use doubly linked lists and
circular linked lists and circular doubly linked lists). Thus my saying
use Java (A PROGRAMMING LANGUAGE) over Delphi (A SCRIPTING LANGUAGE).

There's much more to what you're trying to do, that's why you're not getting it to work properly.

Oh well, have a look at some of Sun's Documentation on Java, I'm sure it'll help :smile:
Re: Need some help with programming Posted by Wild Card on Mon Dec 20th 2004 at 5:29am
Wild Card
2321 posts
Posted 2004-12-20 5:29am
2321 posts 391 snarkmarks Registered: May 20th 2002 Occupation: IT Consultant Location: Ontario, Canada
downloading now, will read some, then head for bed, and read some more tomorow.