Passing Parameters As Pointers?

This is my code that I have so far and I am not entirely sure what I am doing, I need some help please?


This is What I am suppose to have done.



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:
1. Ask the user how many students were surveyed. Dynamically allocate an array with this number of elements.
2. Allow the user to enter the number of movies each student saw into the array. The question for the entry should read : "How many movies did student X see?" where you substitute the number of the student for X. Remember that your array index will start at zero but that you should be asking for student 1, student 2, etc. Do not allow negative numbers to be entered.
3. Write functions to do the following:
a) Sort the array from lowest to highest number of movies viewed.
b) Calculate the average number of movies viewed by the students. The average is the sum of all of the movies viewed divided by the number of students. Display the average number of movies viewed by the students.
c) Determine the median number of movies for all the students. The median is is the middle value of the array, For example, if 5 students were entered, the number of movies viewed by student 3 is the median value. If an even number of students is entered, the median is the average of the 2 values in the middle. Display the median value of the array.
d) Compute the mode of the array. The mode is the number of movies viewed most frequently. For example, in an array of 5 students who viewed 5, 3, 8, 5, and 2 movies, 5 will be the mode because 2 students viewed that number of movies. If the array has no mode (all of the numbers are different), display a message indicating that there is no mode.
4. The array should be passed to each of the functions as a pointer to the array.



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
  // Passing Parameters As Pointers
#include<iostream>
#include <iomanip>

using namespace std;

int main()
{
int *studentnum;
int students_surveyed;
int count;
int total;
double average;
double median;

cout<<"How many student are surveyed?"<< endl;
cin>> students_surveyed;

studentnum = new int [students_surveyed];

cout<<"Write by order, the number of movies watched by each of the students" <<endl;
for (count = 0; count<students_surveyed ; count++)
{
	cout << "Student#"<< count +1 << ":";
	cin >> studentnum [count];
	total += studentnum [count];
}

average = static_cast <double> (total) / students_surveyed;

cout<< "The total of movies watched by all the students is:" << total << "movie." <<endl;

cout<< "The Average of movies watched is:" << average << "movie." << endl;

median = total / 2.0;

cout<< "The median of movies watched is:" << median << "movies." <<endl;

delete [] studentnum;
studentnum = 0;

return 0;
}



How many student are surveyed?
5
Write by order, the number of movies watched by each of the students
Student#1:1
Student#2:1
Student#3:1
Student#4:1
Student#5:1
The total of movies watched by all the students is:70movie.
The Average of movies watched is:14movie.
The median of movies watched is:35movies.

--------------------------------
Process exited with return value 0
Press any key to continue . . .


And This is obviously wrong and I am not sure how to fix it either. :[
Last edited on
Please, what is the Question here ? how to sort ? how to pass an array to function or what ?
Last edited on
How to use pointer to functions for the math and such.
No not that kind of Pointers and math. I mean like pointer to a equation function that does the math.
Topic archived. No new replies allowed.