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
|
//main.cpp
//I also use function because it was good practice
//for me, yet I don't know if I am doing things
//properly.
#include<iostream>
#include<cstdlib>
using namespace std;
int getInput(int *, int, int);//Should this be a void or int?
double getAverage(int *, int, int);//Is this correct? I used my book's ex.
double getMedian(int *, int, int);
int main()
{
int students1 = 0; int movies1 = 0; int number = 0;
getInput(&students1, movies1, number);
getAverage(&students1, movies1, number);
getMedian(&students1,movies1, number);
cout << getAverage(&students1,movies1, number);
cout << getMedian(&students1,movies1, number);
}
int getInput(int *point, int input, int num)
{
cout << "How many students are there to enter? ";
cin >> input;// The user enters # of students.
cout << endl;
point = new int[input]; //Dynamically allocate it. Am I correct?
if (point == 0)
cout << "Error: memory could not be allocated"; //Safety feature.
else
{
cout << "Enter the number of movies watched for: "<<endl;
cout << endl;
for (num = 0; num< input; num++) //counter that seems to work.
{ cout << "Student "<< num+1 <<": ";
cin >> point[num]; //User enters the # of movies watched and
//stores it??
}
return num; //Should return the number of movies? or if void
// remove this?
}
}
double getAverage(int * point, int input, int num)//Correct?
{
double total = 0.0; double average = 0.0;
cout << "The average of movies watched in one month is: "<<endl;
cout <<endl;
for (num = 0; num < input; num++)
total += point[num];
average = (total / input);
return average;
}
double getMedian(int * point, int input, int num)
{
double total = 0.0; double median = 0.0;
cout << "The median of movies watched in one month is: "<<endl;
for (num = 0; num<input; num++)
total += point[num];
median = ((input + 1) / 2);
return median;
delete[] point; //This may be in the wrong place.
}
/*
Output so far:
How many students are there to enter? 2
Enter the number of movies watched for:
Student 1: 3
Student 2: 2
The average of movies watched in one month is:
The median of movies watched in one month is:
The average of movies watched in one month is:
-1.#INDThe median of movies watched in one month is:
0
Press any key to continue . . .
*/
|