/* ************************************************************************** * Program name : 035_Mean_Median_and_Mode (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/14 - first version * ************************************************************************** * Description : (a) Set the initial values to Zero * * (b) Input the course code, no. of student & test result * * (c) List of result in unsorted order * * (d) List of result in sorted order * * (e) Find Mean, Mode and Median * * (f) Try again ? * ************************************************************************** */ #include #include #include void bubblesort(int []); void mean(const int []); void mode(const int [], int []); int Student; // Actual no. of student int main() { // part 1 : declaration int Index; // loop counter const int Arraysize=40; // Maximum no. of student is 40 int Result[Arraysize]; // No. of elements in array Result is 40 const int Grade=11; // Maximum no. of grade int Frequency[11]; // No. of elements in array Frequency is 11 char Coursecode[12]; // A string (array of character) char Again; // Try again ? do { // part 2 : Set the initial values to Zero for (Index=1; Index<=Arraysize; Index++) Result[Index-1]=0; for (Index=1; Index<=11; Index++) Frequency[Index]=0; // part 3 : Input the course code, no. of student & test result cout << "\nPlease input the course code : "; cin >> Coursecode; do { cout << "\n\nHow many student take this courde (1-40) : "; cin >> Student; } while (Student<1 || Student>Arraysize); cout << "\n"; for (Index=1; Index<=Student; Index++) do { cout << "\tEnter the result (1-10) for no." << Index << " : "; cin >> Result[Index-1]; } while (Result[Index-1]<1 || Result[Index-1]>10); // part 4 : List of result in unsorted order cout << "\n\nThe unsorted list of examination is : \n"; for (Index=1; Index<=Student; Index++) cout << Result[Index-1] << "\t"; // part 5 : List of result in sorted order cout << "\n\nThe sorted list of examination is : \n"; bubblesort(Result); // Note (1) for (Index=1; Index<=Student; Index++) cout << Result[Index-1] << "\t"; cout << "\n\n"; system("PAUSE"); // part 6 : Find Mean, Mode and Median cout << "\n Course Code : " << Coursecode << "\n No. of Student : " << Student << "\n"; mode(Result, Frequency); // Note (3) mean(Result); // Note (2) cout << "\nThe Median is : " << Result[(Student-1)/2]; // Note (4) // part 7 : try another number ? cout << "\n\n\t\aTry another number (Y/N) : "; cin >> Again; cout << "\n"; }while (Again=='Y' || Again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } void bubblesort(int Result[]) // Note (1) { int Index_1, Index_2, tempint; for (Index_1=0; Index_1Result[Index_2]) { tempint = Result[Index_1]; Result[Index_1] = Result[Index_2]; Result[Index_2] = tempint; } } void mode(const int Result[],int Frequency[]) // Note (3) { int Index_1,Index_2, Modegrade; for (Index_1=0; Index_1Frequency[Modegrade]) Modegrade = Index_1; cout << "\nThe Mode is : "; for (Index_1=1; Index_1<=10; Index_1++) // Note (7) if (Frequency[Index_1]==Frequency[Modegrade]) cout << Index_1 << " , "; } void mean(const int Result[]) // Note (2) { int Index; float Sum; Sum = 0; for (Index=0; Index