can help me with c++ program?

dorky82

Senior member
Apr 29, 2003
250
0
71
I need help with programming array
its highschool cs class so should be easy for you guys.
My msn is jp82_1@hotmail.com
please email me its due on thursday and i cant figure it out.
I'll pay or give junks that i have.
 

Krakerjak

Senior member
Jul 23, 2001
767
0
0
I think most people are willing to help you "pro bono", unless you are expecting someone to DO you homework for you...
 

dorky82

Senior member
Apr 29, 2003
250
0
71
im almost done with it. I need to find how to count arrays

question is

program that reads in an array of type int. You may assume that there are fewer than 50 entries in the array.
program has to sort numbers and count how many there are

for example
input is -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

output is
N Count
4 2
3 3
2 2
1 4
-1 1
-12 4

I found way to sort highest number to lowest number

I need to figure out how to count intput array and how to input array.


example
 

bleeb

Lifer
Feb 3, 2000
10,868
0
0
Your description and question makes NO sense. I can't correlate the input thats given and the output. What are you asking??
 

PCMarine

Diamond Member
Oct 13, 2002
3,277
0
0
Originally posted by: dorky82
im almost done with it. I need to find how to count arrays

question is

program that reads in an array of type int. You may assume that there are fewer than 50 entries in the array.
program has to sort numbers and count how many there are

for example
input is -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

output is
N Count
4 2
3 3
2 2
1 4
-1 1
-12 4

I found way to sort highest number to lowest number

I need to figure out how to count intput array and how to input array.


example


That's pretty easy, all you need is a simple bubble sort and then a for loop for the count. I'm too tried/lazy/etc to write the program :(
 

PCMarine

Diamond Member
Oct 13, 2002
3,277
0
0
Originally posted by: dorky82
im almost done with it. I need to find how to count arrays

question is

program that reads in an array of type int. You may assume that there are fewer than 50 entries in the array.
program has to sort numbers and count how many there are

for example
input is -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

output is
N Count
4 2
3 3
2 2
1 4
-1 1
-12 4

I found way to sort highest number to lowest number

I need to figure out how to count intput array and how to input array.


example


That's pretty easy, all you need is a simple bubble sort and then a for loop for the count. I'm too tried/lazy/etc to write the program :(
 

xospec1alk

Diamond Member
Mar 4, 2002
4,329
0
0
i see. the program is supposed to read in an array of ints of less than 50 ints. and spit back how many of each number there is rite? dude you already sorted it...another 10 minutes and ur done.
 

dorky82

Senior member
Apr 29, 2003
250
0
71
it looks easy but im having real hard time.

you input

-12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

output will be(without -----)
N for number and Count for number of times that number was inputed
N----- Count
4------- 2
3------- 3
2------- 2
1------- 4
-1------ 1
-12-----4

just simple counting array but i just dont know how to do it.

if you can help me please pm me.
 

bleeb

Lifer
Feb 3, 2000
10,868
0
0
Its probably best to describe how you want to tackle this.

For example, describe some algorithms you think might work...

Since you already have the sorted list...you simply just take the first number, then increment a counter variable until the number changes. Store that variable in some other array (output array) then reset the counter variable and start at that new index in the original array. This is one way to approach this..
 

Krakerjak

Senior member
Jul 23, 2001
767
0
0
You need a counter, and a test variable.
Store the first element to the test variable
compare this to the array incrementing 'i' through the array until you don't get a match. Store this counter and test variable to a 2D array ie. array[0][0] would correspond to the number and the count of times this number appears.

Take this 'i' value in the original array and store it to the test variable, reset the counter, increment, store..... and repeat until the end of the array is reached.

Print out the 2D array with formatting...
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
Great saints alive people...the array is already sorted.

int index;
int count=0;
for (int inum =0;inum<number_of_inputs;inum++)
{
if(inum=0){index=array[inum]; count++;}
else if(array[inum] != index)
{
cout << index << &quot; &quot; << count << endl;
count =1;
index = array[inum];
}else{count++;}
}

prolly a goof somewhere, but should be easy to figure out wtf I wrote.
 

crystal

Platinum Member
Nov 5, 1999
2,424
0
76
Use a HashTable collection. As you loop thru the input array, used the number as the key. There is an if/else check in the loop to see if key (N) exists or not. If not exist, add to hashtable (N,value = 1), else (N, ++value). Then iterate thru the collection and print out its key & value i.e. N & Count. Well you get the ideas. Good luck.
 

dym

Senior member
Jun 11, 2003
578
0
0
That's pretty easy, all you need is a simple bubble sort and then a for loop for the count. I'm too tried/lazy/etc to write the program :(

I agree
 

johnjbruin

Diamond Member
Jul 17, 2001
4,401
1
0
Originally posted by: crystal
Use a HashTable collection. As you loop thru the input array, used the number as the key. There is an if/else check in the loop to see if key (N) exists or not. If not exist, add to hashtable (N,value = 1), else (N, ++value). Then iterate thru the collection and print out its key & value i.e. N & Count. Well you get the ideas. Good luck.

If he could'nt do what he already described, how in the world do you expect him to know hash tables implemented in c++ (java would still have been understandable).

dorky82, just use a for loop to go through the sorted array to count them. It should be pretty easy.