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
|
#include <iostream>
#include <string>
using namespace std;
struct studentType
{
string name;
double gpa;
};
// this function returns the biggest integer in the list.
int getMax(int list[], int size)
{
int result = list[0];
for (int i = 0 ; i < size ; i ++)
{
if (list[i] > result)
result = list[i];
}
return result;
}
int getMax(studentType list[], int size)
{
double result = list[0].gpa;
int index = 0;
for (int i = 0 ; i < size ; i ++)
{
if (list[i].gpa > result)
result = list[i].gpa;
index = i-1;
}
return index;
}
// (a) overload the getMax function to return the student
// with the highest gpa
//...
int main()
{
const int SIZE = 6;
int numbers[SIZE] = {11, 33, 444, 55, 66 -100};
studentType students[6] = {{"john", 3.01}, {"alice", 3.6}, {"liz", 2.5},{"Mike",3.8},
{"Jennifer",4.1},{"Stacey",3.7}
};
cout << getMax(numbers, SIZE) << endl;
int index = getMax(students, 6);
cout<<students[index].name << "\t" << students[index].gpa <<endl;
// (b) call the getMax function using students list and
// print the name and gpa of the student with the highest gpa
//...
return 0;
}
|