Define a class student with the following specification Private members of class student admno integer sname 20 character eng. math, science float total float Public member function of class student ctotal() a function to calculate eng + math + science with float return type. Takedata() Function to accept values for admno, sname, eng, science Showdata() Function to display all the data members on the screen
#include<iostream>
using namespace std;
class student
{
private:
int admno;
char sname[20];
float eng,math,science;
float total;
public:
void get_data()
{
cout<<"enter the addmission number and name of student : " <<endl;
cin>>admno>>sname;
cout <<"enter the marks of student in english , maths , science :"<<endl;
cin>>eng>>math>>science;
}
int ctotal();
void show_data();
};
int student :: ctotal()
{
int total_marks=eng+math+science;
return total_marks;
}
void student :: show_data()
{
cout<<"total marks of student "<<sname;
cout<<" is "<<ctotal() <<" and his admission no. is "<<admno<<endl;
}
int main()
{
student s1,s2;
s1.get_data();
cout<<"Detail of 1st student is as follow :"<<endl;
s1.ctotal();
s1.show_data();
s2.get_data();
cout<<"Detail of 2nd student is as follow :"<<endl;
s2.ctotal();
s2.show_data();
}
output :
enter the addmission number and name of student :
32442
Rahul
enter the marks of student in english , maths , science :
89
80
71
Detail of 1st student is as follow :
total marks of student Rahul is 240 and his admission no. is 32442
enter the addmission number and name of student :
1231
Rohit
enter the marks of student in english , maths , science :
60
70
80
Detail of 2nd student is as follow :
total marks of student Rohit is 210 and his admission no. is 1231
Comments
Post a Comment