bai5-week5
// quan ly sinh vien
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
class SV
{
char ht[25];
int ngay,thang,nam;
char lop[10];
float t,l,h,dtb;
public:
friend istream& operator>>(istream& is,SV &b);
friend ostream& operator<<(ostream& os,SV b);
int operator>(SV);
};
istream& operator>>(istream& is,SV &b)
{fflush(stdin);
cout<<"nhap ten: ";gets(b.ht);
cout<<"nhap lop: ";gets(b.lop);
cout<<"nhap diem toan ly hoa:
";is>>b.t>>b.l>>b.h;
b.dtb=(b.t+b.l+b.h)/3;
return(is);
}
ostream& operator<<(ostream& os,SV b)
{ os<<b.ht<<'
'<<b.lop<<'
'<<b.t<<" "<<b.l<<" "<<b.h<<'
'<<"diem tb: "<<b.dtb;
return(os);
}
int SV::operator>(SV b)
{int kq;
if((dtb-b.dtb)>0) kq=1;
else kq=0;
return(kq);
}
main()
{ int n;SV a[50];
cout<<"nhap danh sach: ";cin>>n;
for(int i=0;i<n;i++)
{ cin>>a[i]; } clrscr();
for(i=0;i<n-1;i++)
for(int j=i;j<n;j++)
if(a[j]>a[i])
{ SV tg=a[i];
a[i]=a[j];
a[j]=tg; }
for(i=0;i<n;i++)
{ cout<<a[i]<<'
'; }
getch();
}
Bạn đang đọc truyện trên: truyentop.pro