#include "stdafx.h"
typedef struct tagSINHVIEN //khai bao cau truc du lieu
{
char MSSV[10];
char Hoten[30];
char Ngsinh[11];
float Diem1,Diem2,dtb;
char XLoai[12];
}
SINHVIEN, *LPSINHVIEN;
void NhapSinhVien(SINHVIEN &sv)
{
printf("Nhap thong tin sinh vien :\n");
printf("MSSV:"); scanf("%s",sv.MSSV);
flushall(); //Giai phong vung dem ban phim
printf("Ho va ten:"); gets(sv.Hoten);
flushall();
printf("Ngay sinh:"); scanf("%s",sv.Ngsinh);
printf("Diem 1,2:"); scanf("%f%f",&sv.Diem1,&sv.Diem2);
}
void NhapDSSV(LPSINHVIEN dssv, int &N)
{
printf("So sinh vien"); scanf("%d",&N);
for(int i = 0;i< N;i++)
{
printf("%d. ",i+1);
NhapSinhVien(dssv[i]);
}
printf("\n");
}
void XuatSinhVien(SINHVIEN sv)
{
printf("%10s ",sv.MSSV);
printf("%s", sv.Hoten);
int len=strlen(sv.Hoten);
for (int i = 0;i <= 31-len;i++)
printf(" ");
printf(" %10s ",sv.Ngsinh);
printf("%3.f%3.1f%3.1f%10s",sv.Diem1,sv.Diem2,(sv. Diem1+sv.Diem2)/2,sv.XLoai);
}
void XuatDSSV(LPSINHVIEN dssv,int N)
{
printf("\n DANH SACH SINH VIEN\n");
for(int i=0; i < N; i++)
{
printf("\n %d. ",i+1);
XuatSinhVien(dssv[i]);
}
printf("\n");
}
void XLoaiSinhVien(SINHVIEN &sv)
{
float N = (sv.Diem1+sv.Diem2) / 2;
if (N >= 8)
strcpy (sv.XLoai,"Gioi");
else if (N >= 7)
strcpy (sv.XLoai,"Kha");
else if (N >= 5)
strcpy (sv.XLoai,"Trung Binh");
else if (N >= 3.5)
strcpy (sv.XLoai,"Yeu");
else
strcpy (sv.XLoai,"Kem");
}
void XLoaiDSSV(LPSINHVIEN dssv,int N)
{
for(int i=0; i <= N; i++)
XLoaiSinhVien(dssv[i]);
}
void SapXepDSSV(LPSINHVIEN dssv,int N)
{
for(int i=0;i <= N-1;i++)
for(int j=i+1;j< N;j++)
if((dssv[i].Diem1+dssv[i].Diem2) >(dssv[j].Diem1+dssv[j].Diem2))
{
SINHVIEN sv;
memcpy( &sv, &(dssv[i]), sizeof(SINHVIEN) );
memcpy( &(dssv[i]) , &(dssv[j]), sizeof(SINHVIEN) );
memcpy( &(dssv[j]) , &sv, sizeof(SINHVIEN) );
}
}
void TimKiemSinhVien(LPSINHVIEN dssv, int N, char *stTen)
{
for( int i=0; i <= N-1; i++ )
if( strcpy( stTen, dssv[i].Hoten) == 1)
{
printf("\n %d. ",i+1);
XuatSinhVien(dssv[i]);
}

}
void main( )
{
SINHVIEN ds[100];
int N;

NhapDSSV( ds, N );
XLoaiDSSV(ds, N );

printf( "Dsach svien:\n" );
XuatDSSV( ds, N );

SapXepDSSV( ds, N );

printf( "Dsach svien sau khi sap xep:\n" );
XuatDSSV( ds, N );
char stTen[100];
flushall();
printf( "Nhap ten svien can tim kiem:" );
gets(stTen);
printf( "Tim kiem va ket qua:\n");
TimKiemSinhVien( ds, N, stTen );
getch();
}