Advertisement
Guest User

c++ lab 1

a guest
Mar 5th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. // Michael Ceng
  2. // CIS 4100
  3. // LAB Extra Credit
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8.  
  9. class movieStats {
  10. private:
  11.     double average, median, mode;
  12.     double *arrayPtr;
  13. public:
  14.     void pollStudents(int);
  15.     double mean(int);
  16.    
  17. };
  18.  
  19. void movieStats::pollStudents(int students) {
  20.  
  21.     arrayPtr = nullptr; // do in constructor
  22.     arrayPtr = new double[students];
  23.  
  24.     for (int i = 0; i < students; i++) {
  25.  
  26.         /*cout << "This value is located at: " << (arrayPtr + i) << endl;
  27.         cout << *(arrayPtr + i) << endl;*/
  28.  
  29.         cout << "Please enter data for student " << i + 1 << ": \n";
  30.         cin >> arrayPtr[i];
  31.     }
  32. }
  33.  
  34. double movieStats::mean(int students) {
  35.     double temp = 0;
  36.     for (int i = 0; i < students; i++) {
  37.         temp += *(arrayPtr + i);
  38.     }
  39.     average = temp/students;
  40.     cout << average << endl;
  41.     return average;
  42. }
  43.  
  44. int main()
  45. {
  46.     movieStats a;
  47.     int size;
  48.  
  49.     cout << "How many students? \n";
  50.     cin >> size;
  51.    
  52.     a.pollStudents(size);
  53.     a.mean(size);
  54.  
  55.     system("pause");
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement