/*Create a class Student with six data members (Roll No., name , marks in English ,Maths and Science , total), write a program with init()
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll;
float eng,math,sci,total;
public:
void init(char [] ,int ,float ,float ,float);
float calctotal(void);
void display(void);
};
void student::init(char nam[25],int rol, float engl, float maths, float scie)
{
strcpy(name,nam);
roll=rol;
eng=engl;
math=maths;
sci=scie;
total=calctotal();
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"English : "<<eng<<endl;
cout<<"Math : "<<math<<endl;
cout<<"Science : "<<sci<<endl;
cout<<"Total : "<<total<<endl;
}
float student::calctotal()
{
return(eng+sci+math);
}
int main()
{
student st1,st2;
char name[25];
int roll;
float eng,sci,math;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st1.init(name,roll,eng,math,sci);
st1.display();
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st2.init(name,roll,eng,math,sci);
st2.display();
getch();
return 0;
}
Tuesday, February 5, 2013
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment