### How do I sort a an array?

I have these codes. I need to sort this array to find the average, mean, and mode.

 ``12345678910111213141516171819202122`` `````` int NumberofStudents; do{ cout << "How many students were surveyed? "; cin >> NumberofStudents; }while (NumberofStudents < 3 || NumberofStudents>10); int *array; array = new int[NumberofStudents]; int i; for (i=0; i<=NumberofStudents-1; i++) { do{ cout << "How many movies did student #"; cout << i+1; cout << " see? "; cin >> array[i]; }while (array[i] < 0); }; ``````
You should find a book or other source that deals with sorting arrays and try doing it yourself.

What you are doing here is essentially asking for someone to write code for you. Not help you find mistakes in your own code.

I speculate this is the reason I am the only reply after four hours.

BTW average and mean are the same thing.

You can use sort function found in the algorithms library
 In common speech yes average can be interpreted as the mean.

In common speech? Math definitions say it is the same too:
 Average. A calculated "central" value of a set of numbers. To calculate: add up all the numbers, then divide by how many numbers there are. Mean. The mean is the average of the numbers: a calculated "central" value of a set of numbers. To calculate: Just add up all the numbers, then divide by how many numbers there are. Median. The middle number (in a sorted list of numbers). To find the Median, place the numbers you are given in value order and find the middle number. Mode. The number which appears most often in a set of numbers.

I agree that it looks like a homework question, but a good portion of the beginner questions here are usually homework questions and homework questions are asked on every site that deals with helping programmers. You could have linked him to articles or tutorials that cover sorting rather than calling out it is a homework question. It being a homework question isn't likely why it wasn't answered though, but rather we get a large amount of questions in the beginner forum and it could have simply been overlooked.

@PSStallion
There are no such things as the "mean average", "median average", and "mode average".

OP is probably looking for average (mean), median, and mode.

There are several ways to sort things.

Two of the simplest are how you would sort a deck of cards.

(a) Take the top card off the unsorted pile and place it in its proper position in the sorted pile. Repeat.

(b) Find the lowest numbered card in the unsorted pile and put it on top of the sorted pile. Repeat.

These are called insertion sort and selection sort respectively.

The mode is the number that appears most often. Finding this is very similar to finding the largest number in an unsorted set: loop through, counting how many elements are the same in a row. For example:

 ```1 2 2 3 4 5 5 5 6 7 7 _ ___ _ _ _____ _ ___ 1 2 1 1 3 1 2 Value 5 has the largest count (there are three of them). Hence the mode is 5. ```

In addition to the loop index, you'll need four variables: longest_mode_count, longest_mode_value, mode_count, and mode_value. Initialize the first two to 1 and the value of the first element.

Hope this helps.
 In common speech yes average can be interpreted as the mean. In common speech? Math definitions say it is the same too:

 There are no such things as the "mean average", "median average", and "mode average".

I direct you both to the very first sentence in the first paragraph.

 Mean, median, and mode are three kinds of "averages". There are many "averages" in statistics, but these are, I think, the three most common, and are certainly the three you are most likely to encounter in your pre-statistics courses, if the topic comes up at all. The "mean" is the "average" you're used to, where you add up all the numbers and then divide by the number of numbers. The "median" is the "middle" value in the list of numbers. To find the median, your numbers have to be listed in numerical order, so you may have to rewrite your list first. The "mode" is the value that occurs most often. If no number is repeated, then there is no mode for the list.

source taken from http://www.purplemath.com/modules/meanmode.htm
Last edited on
Lol to the person who reports my posts, since when is teaching a reportable offense, if anything spreading ignorance is the reportable offense. I take your report for an admittance of your inability to accept that you were indeed wrong.
Ah, but if you scroll down the page a little further:
 (In the above, I've used the term "average" rather casually. The technical definition of "average" is the arithmetic mean: adding up the values and then dividing by the number of values. Since you're probably more familiar with the concept of "average" than with "measure of central tendency", I used the more comfortable term.)

So the person who wrote this is using "average" loosely to mean "measure of central tendency".

The "real" average is the arithmetic mean; the others (median and mode) are other measures of central tendency, but I've never heard anyone call them "averages" before.

I guess it might not be technically wrong to call median and mode as kinds of "averages", if we can trust Wikipedia:
Wikipedia wrote:
However, the word "average" can be used to refer to the median, the mode, or some other central or typical value.

But just keep in mind that in most (almost all, I'd say) cases, when someone refers to the average of a set of data, he/she is probably talking about the arithmetic mean.

But, umm...sorting arrays?
http://www.cplusplus.com/faq/sequences/sequencing/sort-stuff/

Wow, there are people who call median and mode "averages"? I guess that's why they always have to clarify on those standardized tests (SAT, I think?)...
I wouldn't pay too much attention to it. Probably just a troll because I know I didn't report it and I seriously doubt Duoas did.

But if you want to get into it, the averages referenced in that quote isn't the same average that is equated to mean.
 In statistics, an average is defined as the number that measures the central tendency of a given set of numbers. There are a number of different averages including but not limited to: mean, median, mode and range.

I'm right because in statistics, average means something different than mean while average and mean refer to the same thing in other forms of math (algebra and geometry for example). Duoas is right because you don't refer to mean, mode, median, range, etc as you did with mean average, mode average, etc. You are also right because you are arguing the definition from the angle of statistics. We don't know if the OP has statistics knowledge or if he is just doing a homework assignment that tells him to find them (which I'm leaning toward the latter one since he said "average, mean,..."). This all could just be confusing them rather than helping them.
 Ah, but if you scroll down the page a little further: (In the above, I've used the term "average" rather casually. The technical definition of "average" is the arithmetic mean: adding up the values and then dividing by the number of values. Since you're probably more familiar with the concept of "average" than with "measure of central tendency", I used the more comfortable term.) So the person who wrote this is using "average" loosely to mean "measure of central tendency".

Just so your aware two other posts were removed where I basically stated that average does mean "mean" in common speech and is widely accepted as the default but that post got removed also.

 etc as you did with mean average, mode average, etc.

And for the record I was simply stating that they are all types of averages.

 But just keep in mind that in most (almost all, I'd say) cases, when someone refers to the average of a set of data, he/she is probably talking about the arithmetic mean.

I do, and was simply stating it for clarification purposes and then my posts get removed and my clarification gets slandered.
Last edited on
Topic archived. No new replies allowed.