当前位置:
编程学习 >
C#/ASP.NET >>
自动考试系统
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
struct problem
{
int id;
char *pro,*opA,*opB,*opC,*opD;
char answer;
struct problem *link;
};
typedef struct problem PRM;
void list(PRM *head)
{
PRM *p;
p=head->link;
if(p==NULL)printf("nLink talbe is empty!!");
else
while(p!=NULL)
{
printf("nid=%d Question:%sn A.%sn B.%sn C.%sn D.%sn",p->id,p->pro,p->opA,p->opB,p->opC,p->opD);
p=p->link;
}
}
void freelist(PRM *head)
{
PRM *p;
p=head->link;
while(p!=NULL)
{
free(head);
head=p;
p=p->link;
}
}
PRM*findproblem(PRM *head,int id)
{
PRM*p;
PRM*pleft;
p=head->link;
pleft=head;
while(p!=NULL&&p->id!=id){pleft=p;p=p->link;}
return pleft;
}
void add(PRM *head,int id,char *pro,char *opA,char *opB,char *opC,char *opD,int answer)
{
int len;
PRM *p=head;
PRM *tp;
int i=0;
len=head->id;
tp=(PRM *)malloc(sizeof(PRM));
tp->id=id;
tp->answer=answer;
tp->pro="liujun";
tp->opA="p";
tp->opB="p";
tp->opC="p";
tp->opD="p";
strcpy(tp->pro,pro);
strcpy(tp->opA,opA);
strcpy(tp->opB,opB);
strcpy(tp->opC,opC);
strcpy(tp->opD,opD);
tp->link=NULL;
if(len==0){p->link=tp;head->id++;}
else
{p=findproblem(head,id);
tp->link=p->link;
p->link=tp;
head->id++;
}
p=head;
while(p!=NULL)
{
p->id=i++;
p=p->link;}
head->id=i-1;
}
void del(PRM * head,int id)
{PRM *p,*tp;
int i=0;
p=findproblem(head,id);
tp=p->link;
p->link=tp->link;
free(tp);
p=head;
while(p!=NULL)
{
p->id=i++;
p=p->link;}
head->id=i-1;
}
void modify()
{
}
void savetofile(PRM*head)
{
PRM*p=head->link;
FILE*fp;
fp=fopen("data,txt","a");
while(p!=NULL)
{
fprintf(fp,"n%d%20s%d",p->id,p->answer);
p=p->link;
}
fclose(fp);
}
void loadfromfile(PRM *head)
{
PRM *op,*tp;
FILE *fop;
int i=0;
tp=head;
printf("n");
while(tp->link!=NULL)tp=tp->link;
if((fop=fopen("data,txt",