Pages

100 Contemporary Living Room Designs

Sunday, August 12, 2012

PROGRAM TO READ THE NAME AND MARKS OF N STUDENTS AND FIND THE TOPPER

C++ program to accept the details of n students and find the class topper using friend function. Array of objects must be passed to the friend function.

#include<iostream.h>
#include<conio.h>
class student
{
  int total;
  char name[30];
  public:
  void read()
  {
    cout<<"Enter name\n";
    cin>>name;
    cout<<"Enter total mark\n";
    cin>>total;
  }
  friend void find(student *st,int n);
};
void find(student *st,int n)
{
  int i;
  student s;
  student *s1=new student;
  s1=st;
  s=s1[0];
  for(i=0;i<n;i++)
  {
    if(s1[i].total>s.total)
    {
      s=s1[i];
    }
  }
  cout<<"Topper details\n";
  cout<<"Name  : "<<s.name<<endl;
  cout<<"Marks : "<<s.total<<endl;
}
void main()
{
  int i,l;
  clrscr();
  student s1[10];
  cout<<"Enter the number of students\n";
  cin>>l;
  for(i=0;i<l;i++)
  {
    s1[i].read();
  }
  find(s1,l);
  getch();
}

output




No comments:

Post a Comment