You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yw-1113_20/学生选修课程系统设计2.c

426 lines
9.2 KiB

6 years ago
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include"malloc.h"
void prin1();
void choose();
typedef struct subjects
{
int num;
char name[20];
char kind[10];
int stime;
int ttime;
int etime;
int score;
int term;
struct subjects *next;
}SUB;
SUB *head=NULL;
SUB *create_form()
{
SUB *head,*tail,*p;
int num,stime,ttime;
int etime,score,term;
char name[20],kind[10];
int size=sizeof(SUB);
head=tail=NULL;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>޿γ<EFBFBD><EFBFBD><EFBFBD>Ϣ:\n");
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
while(num!=0)
{
p=(SUB *)malloc(size);
p->num=num;
strcpy(p->name,name);
strcpy(p->kind,kind);
p->stime=stime;
p->ttime=ttime;
p->etime=etime;
p->score=score;
p->term=term;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
}
tail->next=NULL;
return head;
}
void savefile()
{
SUB *p;
FILE *fp;
fp=fopen("2.txt","w");
if(fp==NULL)exit(0);
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ѷ<EFBFBD><EFBFBD><EFBFBD>'2.txt'<27>ļ<EFBFBD><C4BC><EFBFBD>\n");
system("pause");
}
void savefile1()
{
SUB *p;
FILE *fp;
fp=fopen("3.txt","w");
if(fp==NULL)exit(0);
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ѷ<EFBFBD><EFBFBD><EFBFBD>'3.txt'<27>ļ<EFBFBD><C4BC><EFBFBD>\n");
system("pause");
}
void readfile()
{
void *myInsert(SUB*);
SUB *newSub;
int num,stime,ttime,etime;
int score,term;
char c,name[20],kind[10],fname[20];
FILE *fp;
fp=fopen("2.txt","r");
while(!feof(fp))
{
newSub=(SUB*)malloc(sizeof(SUB));
fscanf(fp,"%d%s%s%d%d%d%d%d\n",&newSub->num,newSub->name,newSub->kind,&newSub->stime,&newSub->ttime,&newSub->etime,&newSub->score,&newSub->term);
myInsert(newSub);
}
fclose(fp);
}
void prin()
{
SUB *ptr;
head=NULL;
readfile();
if(head==NULL)
{
printf("\n\n\t*********NO RECORDS!************\n");
return;
}
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(ptr=head;ptr;ptr=ptr->next)
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
}
system("pause");
}
void prin1()
{
SUB *ptr;
FILE *fp;
if((fp=fopen("3.txt","r"))==NULL)
{
printf("Cannot open file.\n");
choose();
}
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
while(!feof(fp))
{
ptr=(SUB*)malloc(sizeof(SUB));
fscanf(fp,"%d%s%s%d%d%d%d%d\n",&ptr->num,ptr->name,ptr->kind,&ptr->stime,&ptr->ttime,&ptr->etime,&ptr->score,&ptr->term);
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
}
system("pause");
}
void *myInsert(SUB *subj)
{
SUB *ptr,*ptr2;
ptr=subj;
if(head==NULL)
{
head=ptr;
head->next=NULL;
}
else
{
for(ptr2=head;ptr2;ptr2=ptr2->next)
if(ptr2->next==NULL)
{
ptr2->next=subj;
subj->next=NULL;
break;
}
}
return head;
}
void *insert()
{
SUB *ptr,*subj;
int size=sizeof(SUB);
char ch,ch1;
while(ch!='0')
{
subj=(SUB *)malloc(size);
ptr=subj;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀγ<EFBFBD><EFBFBD><EFBFBD>Ϣ:\n");
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD>:");scanf("%d",&subj->num);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");scanf("%s",&subj->name);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");scanf("%s",&subj->kind);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧʱ:");scanf("%d",&subj->stime);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ѧʱ:");scanf("%d",&subj->ttime);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ:");scanf("%d",&subj->etime);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");scanf("%d",&subj->score);
printf("\n\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");scanf("%d",&subj->term);
myInsert(subj);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD>\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿγ̰<EFBFBD> 0: [ ]\b\b");
ch1=getchar();
ch=getchar();
}
return head;
}
void *del()
{
SUB *p1,*p2;
char ch,ch1;
int num;
while(ch!='0')
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD>Ŀγ̱<EFBFBD><EFBFBD><EFBFBD>:[ ]\b\b\b\b\b");
scanf("%d",&num);
if(head->num==num)
{
p2=head;
head=head->next;
free(p2);
}
if(head==NULL)
return NULL;
p1=head;
p2=head->next;
while(p2)
{
if(p2->num==num)
{
p1->next=p2->next;
free(p2);
}
else
p1=p2;
p2=p1->next;
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD>\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>γ̰<EFBFBD> 0: [ ]\b\b");
ch1=getchar();
ch=getchar();
printf("\nɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>\n");
system("pause");
}
return head;
system("pause");
}
void choose()
{
SUB *p,*q;
int a[5];
int num,total=0,i=0,j;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѡ<EFBFBD>޵Ŀγ̵ı<EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>Կո<D4BF><D5B8>ֿ<EFBFBD>\n");
scanf("%d",&num);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѡ<EFBFBD>޵Ŀγ̵ı<EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0: [ ]\b\b");
while(num!=0)
{
for(p=head;p;p=p->next)
if(p->num==num)
{
total=total+p->score;
a[i]=num;
i++;
}
scanf("%d",&num);
}
if(total<60)
{
printf("ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>Ϊ%d,δ<>ﵽ60,ѡ<><D1A1>ʧ<EFBFBD><CAA7>!\n",total);
system("pause");
}
else
{
FILE *fp;
fp=fopen("3.txt","w");
for(j=0;j<i;j++)
for(q=head;q;q=q->next)
if(q->num==a[j])
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",q->num,q->name,q->kind,q->stime,q->ttime,q->etime,q->score,q->term);
fclose(fp);
printf("\t\t\n*****ѡ<>޳ɹ<DEB3>!****\n");
printf("\n<EFBFBD><EFBFBD>ѡ<EFBFBD>޵Ŀγ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>Ϊ%d,<2C>γ̷ֱ<CCB7>Ϊ:\n",total);
printf("\n<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(j=0;j<i;j++)
for(q=head;q;q=q->next)
if(q->num==a[j])
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",q->num,q->name,q->kind,q->stime,q->ttime,q->etime,q->score,q->term);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'3.txt'<27><>\n");
}
system("pause");
}
void search()
{
int a,num;
int t=1;
char type[10],min[10];
SUB *ptr;
L1:system("cls");
printf("\n\n\t\t**********<2A><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF>ʽ*************\n");
printf("\n\t\t\t1---<2D><><EFBFBD>γ<EFBFBD><CEB3><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>\n");
printf("\n\t\t\t2---<2D><><EFBFBD>γ<EFBFBD><CEB3><EFBFBD><EFBFBD>ʲ<EFBFBD><CAB2><EFBFBD>\n");
printf("\n\t\t\t3---<2D><>ѧ<EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>\n");
printf("\n\t\t\t4---<2D>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>\n");
printf("\n\n\t\t**************************************\n");
printf("\n\nChiose your number(1-4):[ ]\b\b");
scanf("%d",&a);
switch(a)
{
case 1:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĿγ̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",min);
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(ptr=head;ptr;ptr=ptr->next)
if(strcmp(min,ptr->name)==0)
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
if(t)
printf("\t\nδ<EFBFBD>ҵ<EFBFBD>!\n");
t=1;
system("pause");
goto L1;
case 2:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĿγ̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",type);
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(ptr=head;ptr;ptr=ptr->next)
if(strcmp(type,ptr->kind)==0)
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
if(t)
printf("\t\nδ<EFBFBD>ҵ<EFBFBD>!\n");
t=1;
system("pause");
goto L1;
case 3:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĿγ̵<EFBFBD>ѧ<EFBFBD><EFBFBD>:");
scanf("%d",&num);
printf("<EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD> <20><>ѧʱ <20>ڿ<EFBFBD>ѧʱ ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ѧʱ ѧ<><D1A7> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>\n");
for(ptr=head;ptr;ptr=ptr->next)
if(ptr->score==num)
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
if(t)
printf("\n\tδ<EFBFBD>ҵ<EFBFBD>!\n");
t=1;
system("pause");
goto L1;
case 4:break;
}
}
void Mangers()
{
int n,w=1,flag=0,i=3;
char s[8];
char password[7]="1";
do
{
printf("\n\nEnter password:");
scanf("%s",s);
if(!strcmp(s,password))
{
flag=1;
break;
}
else
{
printf("\n\nError! You only have %d times! Enter again:\n",i-1);
i--;
}
}
while(i>0);
if(!flag)
{
printf("you have Enter 3 times!");
exit(0);
}
do
{
system("cls");
printf("\n\n\t\t*********************<2A><><EFBFBD><EFBFBD>Ա<EFBFBD>˵<EFBFBD>***********************\n\n");
printf("\t\t\t\t1---<2D><><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD>\n");
printf("\t\t\t\t2---<2D><>ѯ<EFBFBD>γ<EFBFBD>\n");
printf("\t\t\t\t3---<2D><><EFBFBD>ӿγ<D3BF>\n");
printf("\t\t\t\t4---ɾ<><C9BE><EFBFBD>γ<EFBFBD>\n");
printf("\t\t\t\t5---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>");
printf("\n\n\t\t******************************************************\n");
printf("Chiose your number(1-5):[ ]\b\b");
scanf("%d",&n);
switch(n)
{
case 1:prin();break;
case 2:search();break;
case 3:insert();savefile();break;
case 4:del();savefile();break;
case 5:return;
default:;
}
}
while(w==1);
}
void Students()
{
int n,w=1;
do
{
system("cls");
puts("\n\n\t\t*********************ѧ<><D1A7><EFBFBD>˵<EFBFBD>***********************\n\n");
puts("\t\t\t\t1---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>пγ<D0BF>\n");
puts("\t\t\t\t2---<2D><>ѯ<EFBFBD>γ<EFBFBD><CEB3><EFBFBD>Ϣ\n");
puts("\t\t\t\t3---ѡ<><D1A1>ѡ<EFBFBD>޿γ<DEBF>\n");
puts("\t\t\t\t4---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>޵Ŀγ<C4BF>\n");
puts("\t\t\t\t5---ɾ<><C9BE><EFBFBD><EFBFBD>ѡ<EFBFBD>γ<EFBFBD>\n");
puts("\t\t\t\t6---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>");
puts("\n\n\t\t****************************************************\n");
printf("Chiose your number(1-6):[ ]\b\b");
scanf("%d",&n);
switch(n)
{
case 1:prin();break;
case 2:search();break;
case 3:choose();break;
case 4:prin1();break;
case 5:del();savefile1();break;
case 6:return;
default:;
}
}
while(w==1);
}
int main()
{
int n,w=1;
do
{
system("cls");
puts("\n\n\t\t*********************MENU***********************\n\n");
puts("\t\t\t\t1.<2E>Թ<EFBFBD><D4B9><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ݵ<EFBFBD>¼(password 1)\n");
puts("\t\t\t\t2.<2E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>¼\n");
puts("\t\t\t\t3.<2E>˳<EFBFBD>");
puts("\n\n\t\t************************************************\n");
printf("Chiose your number(1-3):[ ]\b\b");
scanf("%d",&n);
switch(n)
{
case 1:Mangers() ;break;
case 2:Students();break;
case 3:w=0;break;
default:;
}
}
while(w==1);
return 0;
}