C++ program to create class methods and shows how to access the class methods outside of class.
#include<string>
#include<iostream>
using namespace std;
class student
{
private:
int rollNo;
double Percent;
string name;
public:
void GetName(string n) //method taking name of student
{
name=n;
}
void getRoll(int r){rollNo=r;}
double CalPre() //method to calculate percentage
{
int a,b,c,d,e;
cout<<"Enter your 5 subject number out of 100 :";
cin>>a>>b>>c>>d>>e;
Percent=(a+b+c+d+e)/5;
return Percent;
}
void print() //method to print
{
cout<<"rollNo :" <<rollNo<<endl;
cout<<name<<endl;
cout<<"Percentage of student :"<<Percent<<endl;
}
};
int main()
{
student s1;
s1.GetName("Shivam choubey");
s1.getRoll(1837);
s1.CalPre();
s1.print();
}
Enter your 5 subject number out of 100 :55 66 99 78 88 rollNo :1837 Shivam choubey Percentage of student :77
0 Comments
If you have any doubt and suggestion Please let me know