/* Efarmoges: pinakes, synarthseis, mesos oros, mesos, pio syxno stoixeio */ #include #define DATASIZE 50 #define DATARANGE 9 //dedomena sto diasthma 1-9 using namespace std; /* prototypo synarthsewn */ double mean(int data[], int size); double median(int data[], int size); int mode(int freq[], int range, int data[], int size) ; void bubbleSort(int data[], int size); void printArray(int data[], int size); int main(int argc, char *argv[]) { int piosyxno; // to pio syxno stoixeio int frequency[DATARANGE+1] = {0}; /* arxokopoihsh pinaka syxnothtwn */ /* dedomena einai kvdikoi 1-9 */ int data[DATASIZE] = // dedomena {2, 5, 6, 8, 7, 8, 7, 8, 8, 9, 3, 9, 8, 7, 8, 7, 1, 8, 1, 8, 9, 7, 8, 9, 9, 8, 9, 8, 9, 7, 5, 3, 5, 2, 5, 3, 9, 4, 6, 4, 7, 7, 4, 4, 2, 5, 3, 8, 7, 6}; /* epeksergasia dedomenwn */ cout<<"O mesos oros einai "< a[j + 1]) { hold = a[j]; a[j] = a[j + 1]; a[j + 1] = hold; } } } } /* synarthsh mesos oros */ double mean(int codes[], int n) // a pinakas, n megethos pinaka { int total = 0; for (int j = 0; j < n; j++) total += codes[j]; return (double) (total/n); } /* synarthsh gia ton prosdiorismoi tou mesou - xreiazetai thn taksinomhsh */ double median(int codes[], int n) // a pinakas, n megethos pinaka { cout<<"\nMh taksinomhmenos pinakas"; printArray(codes, n); /* ektypwsh */ /* taksinomhsh */ bubbleSort(codes, n); cout<<"\nTaksinomhmenos pinakas"; printArray(codes, n); /* ektypwsh */ if (n%2==1) return (double) codes[n/2]; else return (double)(codes[n/2]+codes[1+n/2])/2; } /* synarthsh gia eyresh deikth megalyterhs syxnothtas */ int mode(int freq[], int range, int codes[], int n) { int maxfreq = 0; /* gia megisth syxnothta */ int maxfreqpos = 0; /* deikths megisths syxnothtas */ /* arxikopoihsh syxnothtwn */ for (int i = 1; i <= range; i++) freq[i] = 0; /* metrhma, eyresh syxnothtas kathe stoixeiou 1-9 */ for (int i = 0; i < n; i++) freq[codes[i]]++; /* eyresh theshs megisths syxnothtas */ for (int i = 1; i <= range; i++) if (freq[i] > maxfreq) { maxfreq = freq[i]; maxfreqpos = i; } return maxfreqpos; }