CLASSES WITH ARRAYS AS DATA MEMBERS

SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class student
{
 char name[30];
 int m[5],i,sum;
 float avg;
 public:
   void get();
   void total();
   void average();
};
void student::get()
{
 cout<<"\nEnter a Name : ";
 cin>>name;
 cout<<"\nEnter the 5 marks : ";
  for(i=0;i<5;i++)
    {
     cin>>m[i];
    }
}
void student::total()
{
 for(i=0;i<5;i++)
  {
   sum+=m[i];
  }
 cout<<"\nSum is "<<sum;
}
void student::average()
{
 avg=sum/5;
 cout<<"\nAverage is "<<avg;
}
void main()
{
 clrscr();
 student JJ;
 JJ.get();
 JJ.total();
 JJ.average();
 getch();
}

OUTPUT :

Enter a Name : JEBASTIN

Enter the 5 marks :
100
99
95
80
100

Sum is 474

Average is  94.8
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: