Skip to main content
Create a class student,stores the details about name,roll no,marks of 5 subject,1.get function accept value of data members,2.display function to display,3.total function to return total of 5 subjects marks.
CODING:  
#include<iostream.h>
#include<conio.h>
class student
{
int roll;
char name[10];
float mark[5],sum;
public:
void get(void);
void total(void);
void disp(void);
};

void student::get(void)
{
int i;
cout<<"NAME   :";
cin>>name;

cout<<"ROLL NO.:";
cin>>roll;

for(i=1;i<=5;i++)
{
cout<<i<<".Subject Marks:";
cin>>mark[i];
}
}

void student::disp(void)
{
int i;
cout<<"\nSTUDENT NAME   :"<<name;
cout<<"\nSTUDENT ROLL NO:"<<roll;
for(i=1;i<=5;i++)
{
cout<<"\n"<<i<<".SUBJECT MARKS:"<<mark[i];
}
}


void student::total(void)
{
int i,sum=0;
for(i=1;i<=5;i++)
{
sum=sum+mark[i];
}
cout<<"\nTOTAL MARKS    :"<<sum;
}

void main()
{
clrscr();
student s1;
s1.get();
s1.disp();
s1.total();
getch();
}

Comments