#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct sv
{
char msv[50],ten[50],lop[50];
float diem;
sv *tiep;
};
sv *dau=NULL, *cuoi;
void tao()
{
sv *p=new sv;
if(dau==NULL)
dau=p;
else
cuoi->tiep=p;
p->tiep=NULL;
cuoi=p;
}
void nhap()
{
int i=0;
while(1)
{
i++;
printf("\n\n Nhap sinh vien thu %d: ",i);
printf("\n Ma sinh vien: ");
char t[50];
fflush(stdin);
gets(t);
if(t[0]==NULL)
return;
tao();
strcpy(cuoi->msv,t);
printf(" Ten: ");
gets(cuoi->ten);
printf(" Lop: ");
fflush(stdin);
gets(cuoi->lop);
printf(" Diem: ");
scanf("%f",&cuoi->diem);
}
}
void gioi()
{
printf("\n\n Ten cac sinh vien co hoc luc gioi la: ");
for(sv *r=dau;r!=NULL;r=r->tiep)
if(r->diem>=8.0)
printf("\n MaSV: %s, Ten: %s, Lop: %s, DiemTK: %g",r->msv,r->ten,r->lop,r->diem);
}
void duoi5()
{
printf("\n\n Cac sinh vien khong du diem: ");
for(sv *r=dau;r!=NULL;r=r->tiep)
if(r->diem<5.0)
printf("\n MaSV: %s, Ten: %s, Lop: %s, DiemTK: %g",r->msv,r->ten,r->lop,r->diem);
}
void ghifile()
{
FILE *fi=fopen("NGUYEN.DAT","wb");
for(sv *r=dau;r!=NULL;r=r->tiep)
if(strncmp(r->ten,"Nguyen",6)==0)
fwrite(&r,sizeof(sv),1,fi);
fclose(fi);
}
void main()
{
nhap();
gioi();
duoi5();
ghifile();
getch();
}
Không có nhận xét nào:
Đăng nhận xét