Вы находитесь на странице: 1из 2

Create a Class Student to represent student information [roll no, Name, Percentage]

.Write a C++ Program to maintain information of 10 students and display the top 5
students based on Percentage :

#include<iostream.h>
#include<conio.h>
#include<string.h>

class student
{
int rn;
float per;
char name[20];
public:
void get()
{
cout << "\n Enter Roll No. : ";
cin >> rn;
cout << "\n Enter percentage : ";
cin >> per;
cout << "\n Enter Name : ";cin >> name;
}
friend void sort(student *);

};
void sort(student *s)
{
student temp;
for(int i=0;i<10;++i)
{
for(int j=1+i;j<10;++j)
{
if(s[i].per < s[j].per)
{
temp.per=s[i].per;
temp.rn=s[i].rn;
strcpy(temp.name,s[i].name);

s[i].per=s[j].per;
s[i].rn=s[j].rn;
strcpy(s[i].name,s[j].name);

s[j].per=temp.per;
s[j].rn=temp.rn;
strcpy(s[j].name,temp.name);
}
}
}
/////////////
for(i=0;i<5;++i)
{
cout << "\n Roll No. : " << s[i].rn;
cout << "\n Name : " << s[i].name;
cout << "\n Percentage : " << s[i].per;
cout << "\n\n\n";
}
}
void main()
{
clrscr();
student S[10];
for(int i=0;i<10;++i)
S[i].get();

sort(S);
getch();
}

Вам также может понравиться