• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can help me with c++ program?

dorky82

Senior member
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.
 
I think most people are willing to help you "pro bono", unless you are expecting someone to DO you homework for you...
 
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
 
Your description and question makes NO sense. I can't correlate the input thats given and the output. What are you asking??
 
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 🙁
 
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 🙁
 
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.
 
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.
 
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..
 
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...
 
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.
 
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.
 
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.
 
Back
Top