Create a class student which stores the detail about roll no,name, marks of 5 subjects, i.e. science, Mathematics, English,C, C++. The class must have the following:
• Get function to accept value of the data members.
• Display function to display values of data members.
• Total function to add marks of all 5 subjects and Store it in the data members
named total.
• Get function to accept value of the data members.
• Display function to display values of data members.
• Total function to add marks of all 5 subjects and Store it in the data members
named total.
#include<iostream>
using namespace std;
class student
{
int no;
char name[10];
int m[5];
int total;
public:
void getdetails();
void display();
void findtotal();
};
void student::getdetails()
{
cout<<"\n Enter no and name";
cin>>no>>name;
findtotal();
}
void student::findtotal()
{ total=0;
for(int i=0;i<5;i++)<5 font="" i="">5>
{
cout<<"\n Enter marks of subject"<<i;
cin>>m[i];
total=total+m[i];
}
}
void student::display()
{
cout<<"\n "<<no<<" "<<name<<" ";
for(int i=0;i<5;i++)<5 font="" i="">5>
{
cout<<" "<<m[i]<<" ";
}
cout<<total;
}
void main()
{
student s1;
s1.getdetails();
s1.display ();
}
using namespace std;
class student
{
int no;
char name[10];
int m[5];
int total;
public:
void getdetails();
void display();
void findtotal();
};
void student::getdetails()
{
cout<<"\n Enter no and name";
cin>>no>>name;
findtotal();
}
void student::findtotal()
{ total=0;
for(int i=0;i<5;i++)<5 font="" i="">5>
{
cout<<"\n Enter marks of subject"<<i;
cin>>m[i];
total=total+m[i];
}
}
void student::display()
{
cout<<"\n "<<no<<" "<<name<<" ";
for(int i=0;i<5;i++)<5 font="" i="">5>
{
cout<<" "<<m[i]<<" ";
}
cout<<total;
}
void main()
{
student s1;
s1.getdetails();
s1.display ();
}