Write a program for inputting the marks of a student in 5 subjects and calculate his average. The number of students whose marks have to be inputted should be entered by the user. Use a class student, an array, a constructor, a destructor and function overloading in your program.

 

#include<iostream.h>
#include<conio.h>
class student
{
private:
int roll_no,n,marks1;
float sum,average;
double a[5];
char name[20];
public:
student()                                             //constructor
{
cout<<"Enter number of students: ";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"Enter name of student: ";
cin>>name;
cout<<"Enter roll no. of student: ";
cin>>roll_no;
for(int j=0;j<5;j++)
{
cout<<"Enter marks of subject no."<<j+1<<" :";
cin>>a[j];                                             //array
marks (a[j]);
}
average=sum/5;
marks(average);
}
}
void marks(double marks1)                     //function overloading
{
sum=sum+marks1;
}
void marks(float marks_obtained)             //function overloading
{
cout<<"The average marks of the student is: "<<marks_obtained;
cout<<endl<<endl;
cout<<"*****************************************\n\n";
sum=0;
}
~student()                                                //destructor
{
cout<<"Destructor";
}
};
void main()
{
clrscr();
student obj1;
gotoxy(25,24); cout<<"Press any key to continue......";
getch();
}

 

< Back