WAP TO ENTER MARKS IN EACH SUBJECTS AND CALCULATE & DISPLAY THE TOTAL MARKS USING FUNCTION
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[30];
float eng,math,sci,tot;
public:
void init();
void caltot();
void display();
};
void student::init()
{
cout<<"Enter rno,name,eng,math & science marks::";
cin>>rno>>name>>eng>>math>>sci;
}
void student::caltot()
{
tot=sci+math+eng;
}
void student::display()
{
cout<<"Rno::"<<rno<<endl
<<"Name::"<<name<<endl
<<"Science::"<<sci<<endl
<<"Math::"<<math<<endl
<<"English::"<<eng<<endl
<<"total::"<<tot<<endl;
}
void main()
{
clrscr();
student s1,s2;
cout<<"Enter student 1 details::"<<endl;
s1.init();
s1.caltot();
s1.display();
cout<<"Enter student 2 details::"<<endl;
s2.init();
s2.caltot();
s2.display();
getch();
}

No comments:
Post a Comment