Answer to Question #185691 in C++ for Laraib

Question #185691

Write a class student with three data members rollno, name and NoOFpresents. It also contains the following member functions

• Input () function to input the values

• Display () to display the values

• CaluculatePercentage () to calculate the percentage of attendance.

• HighestPercentage () to return the highest percentage of the student.

Write a program to that allow user to enter data of five students and number of presents in a month (30 Days). The program should display each student’s data, number of presents and percentage of presents. The program should also display the record of student with highest percentage.



1
Expert's answer
2021-04-26T16:18:13-0400
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
	void input(int num,string nm,int nopr) 
	{
		number = num;
		name = nm;
		noofpresents = nopr;
	}
	string getName() 
	{
		return name;
	}
	double CaluculatePercentage() 
	{
		return ((30.0 - noofpresents) / 30.0) * 100;
	}
	void display() 
	{
		cout << "Student number: " << number << endl;
		cout << "Student name: " << name << endl;
		cout << "Number of student visits to classes: " <<30-noofpresents << endl;
		cout << "Percentage attendance: " << CaluculatePercentage() << endl;
	}
	friend double HighestPercentage(Student* p,int m);
private:
	int number;
	string name;
	int noofpresents;


};
double HighestPercentage(Student* p, int m)
{
	double res = p[0].CaluculatePercentage();
	for (int i = 1; i < m; i++) 
	{
		if (res < p[i].CaluculatePercentage()) 
		{
			res = p[i].CaluculatePercentage();
		}
    }
	return res;
}


int main()
{
	Student test[5];
	int num;
	string nm;
	int pr;
	for (int i = 0; i < 5; i++) 
	{
		cout << "Enter data of the " << i + 1 << " student" << endl;
		cout << "Enter student number: ";
		cin >> num;
		cout << "Enter student name: ";
		cin >> nm;
		cout << "Enter the number of student visits per month: ";
		cin >> pr;
		test[i].input(num, nm, 30 - pr);
		cout << endl;
	}
	// output 
	for (int i = 0; i < 5; i++) 
	{
		test[i].display();
		cout << endl;
	}
	double rate = HighestPercentage(test, 5);
	cout << "Highest attendance rate: " << rate <<" from the following students: "<< endl;
	// output name students
	for (int i = 0; i < 5; i++) 
	{
		if (test[i].CaluculatePercentage() == rate) 
		{
			cout << test[i].getName()<<endl;
		}
	}
	return 0;


}

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
APPROVED BY CLIENTS