Make a function which take a array which store 10 students cgpa. Find the the highest cgpa of student in the array.
#include<iostream>
#include<string>
using namespace std;
struct Student
{
string name;
float cgpa;
public:
Student(){}
void Assign()
{
cout << "Please, enter a name of student: ";
cin >> name;
cout << "Please, enter a cgpa of student: ";
cin >> cgpa;
}
string GetName() { return name; }
float GetCgpa() { return cgpa; }
};
int main()
{
Student arr[10];
for (int i = 0; i < 10; i++)
{
cout << "Please, enter an info about student " << i + 1 << ": \n";
arr[i].Assign();
}
float high = arr[0].GetCgpa();
int j = 0;
for (int i = 0; i < 10; i++)
{
if (arr[i].GetCgpa() > high)
{
high = arr[i].GetCgpa();
j = i;
}
}
cout << "\nThe highest cgpa is " << arr[j].GetCgpa();
cout<<"\nIt has student " << arr[j].GetName();
}
Comments
Leave a comment