#include<cstdio>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
typedef struct thiSinh
{
char ten[51];
char ma[6];
float dtoan,dly,dhoa,tdiem;
}thiSinh;
struct nut
{
thiSinh tS;
struct nut *tiep;
}nut;
typedef struct nut NUT;
typedef NUT *DSLK;
DSLK dau,cuoi;
DSLK p;
float t,to,l,h;
int n,a;
void taoDS (DSLK&,DSLK&);
void giaiPhong(DSLK &,DSLK &);
void duyetDS(DSLK &);
void themCuoi (DSLK&,DSLK& );
void nhapDL(thiSinh &);
void duyetTS (DSLK &dau);
void duyetDToan (DSLK &dau);
#include"khaiBao.h"
int main()
{
taoDS (dau,cuoi);
duyetDS(dau);
duyetTS (dau);
duyetDToan (dau);
giaiPhong(dau,cuoi);
return 0;
}
void taoDS(DSLK &dau,DSLK & cuoi)
{
thiSinh tS;
dau= cuoi= NULL;
nhapDL( tS);
n=1;
while(n!=0)
{
p=(DSLK)malloc (sizeof(NUT));
p->tS=tS;
p->tiep =NULL;
if (dau==NULL)
{
dau=cuoi=p;
}
else
{
cuoi->tiep=p;
cuoi=p;
}
printf ("\tcon thi sinh khong?( chon 0 neu het)\n");
printf ("\tMoi ban chon :");
scanf ("%d",&n);
if (n!=0)
nhapDL (tS);
}
}
void duyetDS(DSLK &dau)
{
p=dau;
printf ("+--------------------------------+------+------+------+------+---------+\n");
printf ("+ HO VA TEN + MA +toan + ly + hoa +tong diem+\n");
printf ("+--------------------------------+------+------+------+------+---------+\n");
while (p!=NULL)
{
printf ("+%-32s",p->tS.ten);
printf ("+%-6s",p->tS.ma);
printf ("+ %5.2f",p->tS.dtoan);
printf ("+ %5.2f",p->tS.dly);
printf ("+ %5.2f",p->tS.dhoa);
printf ("+%8.2f +\n",p->tS.tdiem);
p=p->tiep;
}
printf ("+--------------------------------+------+------+------+------+---------+");
}
void giaiPhong(DSLK&dau,DSLK&cuoi)
{
p=dau;
while (dau!=NULL)
{
dau=dau->tiep;
free(p);
p=dau;
}
dau=cuoi=NULL;
}
void nhapDL(thiSinh &tS)
{
printf ("nhap ho ten thi sinh ");
fflush (stdin);
gets (tS.ten);
printf ("nhap ma thi sinh ");
gets (tS.ma);
printf ("nhap diem toan ");
scanf ("%f",&t);
tS.dtoan=t;
printf ("nhap diem ly ");
scanf ("%f",&t);
tS.dly=t;
printf ("nhap diem hoa ");
scanf ("%f",&t);
tS.dhoa=t;
tS.tdiem=tS.dtoan+tS.dly+tS.dhoa;
}
void duyetTS(DSLK &dau)
{
p=dau;
printf ("\n\n\t\t CAC THI SINH DAU LA:\n");
while (p!=NULL)
{
t=p->tS.tdiem;
to=p->tS.dtoan;
l=p->tS.dly;
h=p->tS.dhoa;
if ((t>15) & (to!=0) &(l!=0)&(h!=0))
{
printf ("Ho ten thi sinh: %s ,",p->tS.ten);
printf ("co diem la:%f\n",p->tS.tdiem);
}
p=p->tiep;
}
}
void duyetDToan (DSLK & dau)
{
p=dau;
a=0;
printf ("\n");
while (p!=NULL)
{
to=p->tS.dtoan;
if (to>9)
{
printf ("Ho ten thi sinh: %s ,",p->tS.ten);
printf ("co diem toan la:%f\n",p->tS.dtoan);
a=a+1;
}
p=p->tiep;
}
printf ("CO %d THI SINH DIEM TOAN LON HON 9\n",a);
}