Answer to Question #321180 in C++ for sanwal

Question #321180

Make a function which take a array which store 10 students cgpa. Find the the highest cgpa of student in the array.


1
Expert's answer
2022-04-10T05:24:03-0400
#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();
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog