Sunday, 7 December 2014

C++ program to print details of student marks list

#include<constream.h>
int x=0,a[10];//global variables//
class stdn
{
 private:
  int sno,m1,m2,m3,total,avg,rank;
  char sname[10],grade;
 public:
  void get();
  void put();

};
 void stdn::get()
 {
  x++;
  cout<<"\nenter sno,sname,m1,m2,m3:";
  cin>>sno>>sname>>m1>>m2>>m3;

  total=m1+m2+m3;
  avg=total/3;
  a[x]=total;

 }
 void stdn::put()
 {
  if(m1>=35&&m2>=35&&m3>=35)
  {
   if(avg>=65)
   grade='A';
   else if(avg<65&&avg>=50)
   grade='B';
   else if(avg<50&&avg>=35)
   grade='C';
   for(int i=1;i<=x;i++)
   if(total==a[i])
   {
    rank=i;
    break;
   }

  }
  else
  {
   grade='F';
   rank=0;
  }
  cout<<sno<<"\t"<<sname<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<total<<"\t"<<avg<<"\t"<<grade<<"\t"<<rank;
 }
 void main()
 {
  clrscr();
  stdn s[10];
  int n,i,j;
  cout<<"\nenter n:";
  cin>>n;
  for(i=0;i<n;i++)
  {
   s[i].get();
  }
  for(i=1;i<=x;i++)
  for(j=1;j<=x;j++)
  {
   if(a[i]>a[j])
   {
    int t=a[i];a[i]=a[j];a[j]=t;
   }
  }

  cout<<"                      STUDENT MARKSLIST\n";
  cout<<"\n....................................................................\n";
  cout<<"sno\tsname\tm1\tm2\tm3\ttotal\tavg\tgrade\trank";
  cout<<"\n....................................................................\n";
  for(i=0;i<n;i++)
  {
   s[i].put();
   cout<<"\n";
  }
  cout<<"\n.....................................................................\n";
  cout<<"\n'F'represents Fail and '0'represents no rank issued";
  getch();
 }