Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that can be used to gather statistical data about the number of

ID: 3772938 • Letter: W

Question

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 perform the following steps a) Ask the user how many students were surveyed. An array of integers with this many elements should then be dynamically allocated using b) Allow the user to enter the number of movies each student saw in a ) Calculate and display the statistics: average, median and mode 1. What is mode and how do you calculate it? In Statistics, the mode the new operator. month into the array of the values entered of a set of values is a value that occurs most often. Write a function called findMode that accepts as arguments the following a. An array of integers b. An integer that indicates the number of elements in the arr For example int students = new int [numo fstudents]; Here students is a pointer to an array we just allocated using new. Even though students is a pointer to an array, it can be used as an array by indexing into it, as students [i] etoc Assume students now has the values indicating the number of movies watched by each student. 5o to calculate the mode of the values in the array you will call the function findMode as follows:

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;


double findMean(int *, int);
double findMedian(int *, int);
int findMode(int *, int);

int main()
{

int *studentArray;   
int noOfStudents;

cout << "Number of students surveyed: ";
cin >> noOfStudents;
while (noOfStudents < 0)
  return 0;

studentArray = new int[noOfStudents];

for (int count = 0; count < noOfStudents; count++)
{
  cout << "Number of movies seen by Student No" << (count + 1) << ": ";
  cin >> studentArray[count];

  while (studentArray[count] < 0)
  {
   cout << "Please Try Again ";
   cout << " Number of movies say by Person #" << (count + 1) << ": ";
   cin >> studentArray[count];
  }

}

cout << "Average number of movies watched in a month: ";
cout << findMean(studentArray, noOfStudents) << endl;

cout << " Mode of the number of movies watched in a month: ";
cout << findMode(studentArray, noOfStudents) << endl;

cout << " Median of the number of movies watched in a month: ";
cout << findMedian(studentArray, noOfStudents) << endl;

delete[] studentArray;
studentArray = 0;  

return 0;
}

double findMean(int *studentArray, int noOfStudents)
{
double total = 0;
double average;

for (int count = 0; count < noOfStudents; count++)
{
  total += studentArray[count];
}
average = total / noOfStudents;
return average;
}

double findMedian(int *studentArray, int noOfStudents)
{
sort(&studentArray[0], &studentArray[noOfStudents]);
double median = size % 2 ? a[size / 2] : (a[size / 2 - 1] + a[size / 2]) / 2;
return median;
}

int findMode(int *studentArray, int noOfStudents)
{
int mode = 0;
int val = 0;
int index;

for (index = 0; index < noOfStudents; index++)
{

  if (*(studentArray + index) == *(studentArray + (index + 1)))
  {
   mode++;
   val = *(studentArray + index);
  }
}
  if (val > 0)
   return val;
  else
   return -1;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote