In: Computer Science
Program:
#include<iostream>
#include<string>
using namespace std;
class Student
{
string name;
int registrationNumber;
float percentage;
public:
void Read(string n, int r, float p)
{
name=n;
registrationNumber=r;
percentage=p;
}
void Display()
{
cout<<"\nStudent Information:\n";
cout<<"-------------------------------\n";
cout<<"Name: "<<name<<endl;
cout<<"Registration number:
"<<registrationNumber<<endl;
cout<<"Percentage: "<<percentage<<endl;
}
void CalculateGrade()
{
if(percentage>=80 && percentage<=100)
{
cout<<"Grade : A";
}
else if(percentage>=60 && percentage<80)
{
cout<<"Grade : B";
}
else if(percentage>=40 && percentage<60)
{
cout<<"Grade : C";
}
else
{
cout<<"Grade : D";
}
}
};
int main()
{
string n;
int r;
float p;
cout<<"Enter Student name: ";
getline(cin,n);
cout<<"Enter Registration number: ";
cin>>r;
cout<<"Enter Percentage: ";
cin>>p;
Student stud;
stud.Read(n,r,p);
stud.Display();
stud.CalculateGrade();
return 0;
}
Output: