Sie sind auf Seite 1von 2

7.

Create a class to store student information with data members as roll no, name, marks in
3subjects total and average using constructor where ever required.
#include<iostream.h>
#include<conio.h>
class student
{
private:
int rollnumber;
char name[10];
int emarks,cppmarks,mmarks;
int totalmarks,saverage;
public:
student()
{
cout<<"Enter the student rollnumber ";
cin>>rollnumber;
cout<<"Enter the student name ";
cin>>name;
cout<<"Enter the student marks in English ";
cin>>emarks;
cout<<"Enter the student marks in C++ ";
cin>>cppmarks;
cout<<"Enter the student marks Discrete Mathematics ";
cin>>mmarks;
}
void addmarks()
{
totalmarks=emarks+cppmarks+mmarks;
}
void average()
{
saverage=totalmarks/3;
}
void display()
{
cout<<"Student roll number "<<rollnumber<<endl<<"Student name "<<name<<endl;
cout<<"Student English marks "<<emarks<<endl;
cout<<"student C++ marks "<<cppmarks<<endl;

cout<<"Student Discrete mathematics marks "<<mmarks<<endl;


cout<<"Total marks "<<totalmarks<<endl<<"Average "<<saverage;
}
};
main()
{
clrscr();
student s1;
s1.addmarks();
s1.average();
s1.display();
getch();
}
Output of this program
Enter the student roll number 1818
Enter the student name Johan
Enter the student marks in English 89
Enter the student marks in C++ 90
Enter the student marks in Discrete Mathematics 99
Student roll number 1818
Student name Johan
Student English marks 89
Student C++ marks 90
Student Discrete mathematics marks 99
Total marks 278
Average 92

Das könnte Ihnen auch gefallen