Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Array Analysis?????

Posted on 1998-06-15
3
Medium Priority
?
282 Views
Last Modified: 2010-04-04
I have an array with up to 200 numbers in it and need to find out how to go about getting the frequencies of each number in the array. IE.

In the array I have - 1 2 2 3 2 4 3
 i need to write the program that will tell me there are 3 number two's, 1 number one, 2 threes, and one four.

I have used one of those memo thing to collect the numbers and then i convert them into numbers for the array.  

I desperatly need this help before an exam tommorow!!

CAN ANYBODY HELP????????????
0
Comment
Question by:Dave091277
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1352861
Is there a range to these numbers, I mean, say from 1 to 50?
0
 
LVL 1

Expert Comment

by:pjdb
ID: 1352862
Which version of Delphi?
Do you know the number of value before the start of the process?
Is 200 the absolute maximum of values, or is it only an example?
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 600 total points
ID: 1352863
Dave, try this:

procedure TForm1.Button1Click(Sender: TObject);
var iIntArray: array[1..7] of integer;
    iCounter: Integer;
    iArrayValue: Integer;
begin
{populate the array}
iIntArray[1] := 1;
iIntArray[2] := 2;
iIntArray[3] := 2;
iIntArray[4] := 3;
iIntArray[5] := 2;
iIntArray[6] := 4;
iIntArray[7] := 3;
{Here we'll use a listbox to display the counts (frequency) of
 each number, we start with a zero count to initialize}
for iCounter := 1 to High(iIntArray)  do
    Begin
    ListBox1.Items.Add('0');
    end;

{Now we scan the array to get the frequency of the numbers}
{Code broken down for simplicity and understanding}
For iCounter := 1 to High(iIntArray) do
   Begin
   iArrayValue := iIntArray[iCounter];
   ListBox1.Items[iArrayValue-1] :=
        IntToStr(StrToInt(ListBox1.Items[iArrayValue-1]) + 1);
   end;

{Done counting, now let's pretty up the results}
For iCounter := 1 to High(iIntArray) do
   Begin
   ListBox1.Items[iCounter-1] :=
            IntToStr(iCounter) + '''s count is ' +
                ListBox1.Items[iCounter-1];

   end;

end;



Good luck with your project!
Pegasus
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question