Question: /*Movie Statistics Write a program that can be used to gather statistical data about the number of movies college students see in a month. The
/*Movie Statistics
Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user to enter the number of movies each student has seen. The program should then calculate the average, median, and mode of the values entered.
Below is the bottom half of the code. There are about 30 some lines that needs to be created above this. */ // The idea is to set currentFreq to 1 for each new // value that is encountered. The variable currentFreq is // incremented each time we find an array item that is the // same value as the previous one. The variable mode keeps // track of the largest value of currentFreq seen so far. while (p < arr + num) { if (*p == *(p-1)) { currentFreq++; if (currentFreq > modeFreq) { mode = *p; modeFreq = currentFreq; } } else { currentFreq = 1; } p++; } if (modeFreq == 1) return -1; else return mode; }
/********************************************* * average * * compute average of an array of num entries * **********************************************/ double average(int arr[], int num) { int total = 0; double ave;
for (int count = 0; count < num; count++) { total += arr[count]; } ave = total / double(num); return ave; }
/***************************** * getNumber * * Use for input validation. * *****************************/ void getNumber(int &num) { cin >> num; while (num < 0) { cout << "Number cannot be negative: Please enter a nonnegative value: "; cin >> num; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
