Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int NUMB_STUD = 5; // Number of student records (ROWS)
- const int NUMB_GRADES = 3; // " " grades per student (COLUMNS)
- void displayGrades(const int arr[][NUMB_GRADES], const int rowSize);
- void getAverage(const int arr[][NUMB_GRADES], const int rowSize);
- void getHighest(const int arr[][NUMB_GRADES], const int rowSize);
- int main()
- {
- int grades[NUMB_STUD][NUMB_GRADES] = { { 96, 91, 100 },
- {88, 93, 84},
- {70, 75, 83},
- {67, 62, 67},
- {98, 85, 86}
- };
- displayGrades(grades, NUMB_STUD);
- getAverage(grades, NUMB_STUD);
- getHighest(grades, NUMB_STUD);
- system("Pause");
- return 0;
- }
- void displayGrades(const int arr[][NUMB_GRADES], const int rowSize)
- {
- cout << "STUDENT GRADES" << endl;
- for (int r = 0; r < rowSize; r++)
- {
- cout << "Student " << r + 1 << " Grades: ";
- for (int c = 0; c < NUMB_GRADES; c++)
- cout << setw(5) << arr[r][c];
- cout << endl;
- }
- cout << endl << endl;
- }
- void getAverage(const int arr[][NUMB_GRADES], const int rowSize)
- {
- float sum = 0.0;
- float average;
- cout << "AVERAGE OF GRADES FOR EACH STUDENT" << endl;
- cout << setprecision(1) << fixed;
- for (int r = 0; r < rowSize; r++)
- {
- cout << "Student " << r + 1 << " Grades: ";
- for (int c = 0; c < NUMB_GRADES; c++)
- sum += arr[r][c];
- average = (sum / NUMB_GRADES);
- cout << setw(5) << average;
- cout << endl;
- }
- cout << endl << endl;
- }
- void getHighest(const int arr[][NUMB_GRADES], const int rowSize)
- {
- cout << "HIGHEST GRADE FOR EACH EXAM" << endl;
- int max;
- for (int c = 0; c < NUMB_GRADES; c++)
- cout << setw(8) << right << "Exam " << c + 1;
- cout << endl;
- for (int c = 0; c < NUMB_GRADES; c++)
- {
- max = arr[0][c];
- for (int r = 0; r < rowSize; r++)
- if (max < arr[0][c])
- {
- max = arr[0][c];
- }
- cout << setw(9) << max;
- }
- cout << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment