Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Student {
- public:
- string name;
- double grade;
- int age;
- Student(string n, double g, int a) : name(n), grade(g), age(a) {}
- };
- void averageAge(Student arr[], int size) {
- int sum = 0;
- for (int i = 0; i < size; i++) {
- sum = sum + arr[i].age;
- }
- int result = sum / size;
- cout << "The avg age is:"<< result <<endl;
- }
- int main() {
- Student st1("Chefo", 5, 17);
- Student st2("Georgi", 3, 17);
- Student st3("Atanas", 6, 16);
- Student st4("Stefan", 4, 17);
- Student st5("Ivan", 5, 16);
- Student students[5] = { st1, st2, st3 , st4, st5 };
- int size = sizeof(students) / sizeof(students[0]);
- averageAge(students, size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement