Docstoc

copy rank

Document Sample
copy rank Powered By Docstoc
					/* Write a C++ program to read records of n number of students in an array
  of objects and print the lists of students in the following format.
                        List of students
  Name         Roll No Average Marks               Grade
  Student class must contain name,roll no,marks in four subjects and grade.
  also include the functions read_data(),compute_grade and disp_data()
  Also print the Rank list. */

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
class student
{
 char name[20];
 int no;
 int mark1,mark2,mark3,mark4;
 char grade;
 int rank;
 public:
 float avg;
   void read_data();
   student printr(student *,int);
   void print(int j)
   {
    cout<<j+1<<"\t "<<name<<"\t"<<no<<endl;
   }
   void compute_grade()
   {
  avg=(mark1+mark2+mark3+mark4)/4;
  if(avg>=80)
   grade='A';
  else if((avg>=60)&&(avg<80))
   grade='B';
  else if((avg>=50)&&(avg<60))
   grade='C';
  else
   grade='D';
  }

  void disp_data();
};

void student::read_data()
{
  cout<<"\nEnter your name :";
  cin>>name;
  cout<<"\nRoll Number :";
  cin>>no;
  cout<<"\nMarks in four subjects :";
    cin>>mark1>>mark2>>mark3>>mark4;
}

void student::disp_data()
{
 cout<<name<<setw(15)<<no<<setw(17)<<avg<<"\t\t"<<grade<<endl;
}

student student::printr(student ab[],int n)
{
 char name1[20];
 int no1,i;
 float avg1;
 for(i=0;i<n-1;i++)
 {
  for(int j=i+1;j<n;j++)
  {
   if((ab[j].avg)>=(ab[i].avg))
   {
    strcpy(name1,ab[j].name);
    strcpy(ab[j].name,ab[i].name);
    strcpy(ab[i].name,name1);

    avg1=ab[j].avg;
    ab[j].avg=ab[i].avg;
    ab[i].avg=avg1;

    no1=ab[j].no;
    ab[j].no=ab[i].no;
    ab[i].no=no1;
   }
  }
 }
 return ab[100];
}

int main()
{
 clrscr();
 int n,i;
 student ab[100];
 cout<<"\nEnter no.of students :";
 cin>>n;
 for(i=0;i<n;i++)
 {
 ab[i].read_data();
 ab[i].compute_grade();
 }
 cout<<"\nNAME            ROLL NO             AVERAGE MARKS   GRADE\n";
 for(i=0;i<n;i++)
{
ab[i].disp_data();
}

  ab[0].printr(ab,n);
 cout<<"\nRANK          NAME   ROLL NO\n";
 for(i=0;i<n;i++)
 {
  ab[i].print(i);
 }
 getch();
 return 0;
}

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:3
posted:10/17/2012
language:
pages:3
Description: C programming, C programming