Thanks alot guys,.... I've been reading on this a lot for the past don't know how many hours.
I mannage to understand a bit.
laserlight, I went through that site but It was kind of hard to understand completely. About the Bubble sort code,
Code:
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
for (i = (array_size - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
}
How will the output turn out?
therabidwombat: Thanks a lot! I mannaged to understand the basic already.
But what I noticed in the lecture slides provided by the lecturer is that all the values in the arrays are all fixed. For example
Code:
const int responseSize = 99;
response[ responseSize ] =
{ 6, 7, 8, 9, 8, 7, 8, 9, 8, 9,
7, 8, 9, 5, 9, 8, 7, 8, 7, 8,
7, 8, 9, 8, 9, 8, 9, 7, 8, 9,
7, 8, 9, 8, 9, 8, 9, 7, 5, 3,
5, 6, 7, 2, 5, 3, 9, 4, 6, 4,
7, 8, 9, 6, 8, 7, 8, 9, 7, 8,
7, 4, 4, 2, 5, 3, 8, 7, 5, 6,
4, 5, 6, 1, 6, 5, 7, 8, 7 };
I understand that all these numbers becomes the values stored in the arrays, but how do we input our own values to be stored? I can't seem to get any info on that.
There is more which I don't understand. Well actually the code starts with this:
Code:
#include <iostream.h>
#include<iomanip.h>
void mean(const int[], int);
void median(int[], int)
void mode(int[], int[], int)
void bubbleSort(const int[], int);
int main()
{
const int responseSize = 99;
response[ responseSize ] =
{ 6, 7, 8, 9, 8, 7, 8, 9, 8, 9,
7, 8, 9, 5, 9, 8, 7, 8, 7, 8,
7, 8, 9, 8, 9, 8, 9, 7, 8, 9,
7, 8, 9, 8, 9, 8, 9, 7, 5, 3,
5, 6, 7, 2, 5, 3, 9, 4, 6, 4,
7, 8, 9, 6, 8, 7, 8, 9, 7, 8,
7, 4, 4, 2, 5, 3, 8, 7, 5, 6,
4, 5, 6, 1, 6, 5, 7, 8, 7 };
mean( response, responseSize );
median( response, responseSize );
mode( frequency, response, responseSize );
return 0;
}
...
...
then it goes on to defining mean then median...
here's the code for defining median:
Code:
void median( int answer[], int size )
{
cout << "\n********\n Median\n********\n"
<< "The unsorted array of responses is";
printArray( answer, size );
bubbleSort( answer, size );
cout << "\n\nThe sorted array is";
printArray( answer, size );
cout << "\n\nThe median is element " << size / 2
<< " of\nthe sorted " << size
<< " element array.\nFor this run the median is "
<< answer[ size / 2 ] << "\n\n";
and the output for the median is:
Code:
********
Median
********
The unsorted array of responses is
6 7 8 9 8 7 8 9 8 9 7 8 9 5 9 8 7 8 7 8
6 7 8 9 3 9 8 7 8 7 7 8 9 8 9 8 9 7 8 9
6 7 8 7 8 7 9 8 9 2 7 8 9 8 9 8 9 7 5 3
5 6 7 2 5 3 9 4 6 4 7 8 9 6 8 7 8 9 7 8
7 4 4 2 5 3 8 7 5 6 4 5 6 1 6 5 7 8 7
The sorted array is
1 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 5
5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
The median is element 49 of
the sorted 99 element array.
For this run the median is 7
What I don't understand is how did they values get all sorted up. I noticed that the sorting was done by this part of the code:
Code:
printArray( answer, size );
But how? How was answer and size defined?
and, to dwks: Yeah I did check that out. The explanation seems to be too general and less technical. Thanks anyway.