1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <iostream>
using namespace std;
void getNumMovies(int [], int);
void getAverage(int [], int);
void sortArray(int [], int);
void getMean(int *, int);
void getMode(int *, int);
int main ()
{
int number;
cout<<"How many students were surveyed?: ";
cin>>number;
cout<<endl;
int array1[number];
getNumMovies(array1, number);
system("pause");
return 0;
}//end of main function
//getNumMovies() Definition
void getNumMovies(int array2[], int size2)
{
for(int index = 0; index < size2; index++)
{
cout<<"How many movies student "<<(index + 1)<<" watched?: ";
cin>>array2[index];
cout<<endl;
}//end for loop
getAverage(array2, size2);
}//end of getNumMovies()
//getAverage() Definition
void getAverage(int array3[], int size3)
{
double average;
double sum = 0;
for(int index = 0; index < size3; index++)
{
sum = sum + array3[index];
}
average = (sum)/(size3);
cout<<"This is the average: "<<average;
cout<<endl;
sortArray(array3, size3);
}//end of getAverage()
//sortArray() Definition
void sortArray(int array4[], int size4)
{
int temp;
bool swap;
do
{ swap = false;
for(int count = 0; count < (size4 - 1); count++)
{
if( array4[count] > array4[count + 1])
{
temp = array4[count];
array4[count] = array4[count + 1];
array4[count + 1] = temp;
swap = true;
}//end if
}//end for
}while (swap);//end do-while
getMean(array4, size4);
getMode(array4, size4);
}//end of sortArray()
//getMean() Definition
void getMean(int *array5, int size5)
{
int remainder = (size5)%(2);
int number = (size5)/(2);
double meanAvg;
if( remainder > 0 || remainder < 0 )
{
cout<<"This is the mean: "<<*(array5 + number)<<endl;
}//end if
else
{
double temp;
temp = *(array5 + number) + *(array5 + (number - 1));
meanAvg = temp/2;
cout<<"This is the mean: "<<meanAvg<<endl;
}//end else
}//end of getMean()
//getMode() Definition
void getMode(int *array6, int size6)
{
int dummy = 0;
for(int counter = 1; counter < size6; counter++)
{
if(*array6 == *(array6 + counter))
dummy++;
}//end for loop
cout<<dummy<<endl;
}//end of getMode()
|