danh sach c++
Đặt văn bản tại đây...#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
#include<string.h>
typedef struct
{
char ho[10];
char ten[10];
char msv[10];
double dtb;
}sv;
typedef sv mang[100];
void nhapsv(mang a,int &n)
{
cout<<"nhap so sv la:";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"nhap sv thu"<<i<<"la:"<<endl;
cout<<"nhap ho:";
gets(a[i].ho);
cout<<"nhap ten:";
gets(a[i].ten);
cout<<"nhap ma sv:";
gets(a[i].msv);
cout<<"nhap dtb:";
cin>>a[i].dtb;
}
}
void insv(mang a,int n)
{
cout<<"DANH SACH SV:"<<endl;
cout<<"ho"<<setw(8)<<"ten"<<setw(8)<<"msv"<<setw(8)<<"dtb"<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i].ho<<setw(8)<<a[i].ten<<setw(8)<<a[i].msv<<setw(8)<<a[i].dtb<<endl;
}
}
sv maxsv(mang a,int n)
{
sv tam;
tam.dtb=a[0].dtb;
for(int i=1;i<n;i++)
{ if(a[i].dtb>tam.dtb)
tam=a[i]; }
return tam;
}
sv minsv(mang a,int n)
{
sv tam1;
tam1.dtb=a[0].dtb;
for(int i=1;i<n;i++)
{ if(a[i].dtb<tam1.dtb)
tam1=a[i];}
return tam1;
}
void sap_xep(mang a,int n)
{
sv tg;
for(int i=0;i<=n-1;i++)
for(int j=i+1;j<=n;j++)
if(strcmp(a[i].ten,a[j].ten)>0)
{
tg=a[i];
a[i]=a[j];
a[j]=tg;
}
}
main()
{
clrscr();
mang a;
int n;
nhapsv(a,n);
insv(a,n);
cout<<endl;
sv tam;
tam=maxsv(a,n);
cout<<"ten sv co dtb lon nhat la:"<<tam.ten<<setw(8)<<tam.dtb<<endl;
/*sv tam1;
tam1=minsv(a,n);
cout<<"ten sv co dtb nho nhat la:"<<tam1.ten<<setw(8)<<tam1.dtb<<endl;*/
cout<<"danh sach sv sau khi sap xep la:"<<endl;
sap_xep(a,n);
insv(a,n);
getch();
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top