parent
7ada371edf
commit
1ba1070179
@ -0,0 +1,332 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#define len sizeof(struct grade)
|
||||
struct grade
|
||||
{
|
||||
char id[10];
|
||||
char clas[10];
|
||||
char name[20];
|
||||
float score1;
|
||||
float score2;
|
||||
float score3;
|
||||
float score;
|
||||
struct grade *next;
|
||||
struct grade *prev;
|
||||
};
|
||||
void print()
|
||||
{
|
||||
int i;
|
||||
for(i=1;i<=30;i++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
};
|
||||
void menu(struct grade *head,struct grade *tail)
|
||||
{
|
||||
void student1(struct grade *head);
|
||||
void delet(struct grade *head,struct grade *tail);
|
||||
void printgrade(struct grade *head,struct grade *tail);
|
||||
void selecty(struct grade *head,struct grade *tail);
|
||||
void arra(struct grade *head,struct grade *tail);
|
||||
char c;
|
||||
print();
|
||||
printf("1.input\n");
|
||||
print();
|
||||
printf("2.delete\n");
|
||||
print();
|
||||
printf("3.select\n");
|
||||
print();
|
||||
printf("4.order\n");
|
||||
print();
|
||||
printf("5.output\n");
|
||||
print();
|
||||
printf("6.quit\n");
|
||||
printf("please input your option\n");
|
||||
scanf("%s",&c);
|
||||
switch(c)
|
||||
{
|
||||
case'1':student1(head);break;
|
||||
case'2':delet(head,tail);break;
|
||||
case'3':selecty(head,tail);break;
|
||||
case'4':arra(head,tail);break;
|
||||
case'5':printgrade(head,tail);break;
|
||||
case'6':break;
|
||||
default:printf("Wrong input");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void printgrade1(struct grade *p)
|
||||
{
|
||||
printf("%s,",p->id);
|
||||
printf("%s,",p->clas);
|
||||
printf("%s,",p->name);
|
||||
printf("%4.1f,",p->score1);
|
||||
printf("%4.1f,",p->score2);
|
||||
printf("%4.1f,",p->score3);
|
||||
printf("%5.1f",p->score);
|
||||
printf("\n");
|
||||
}
|
||||
void printgrade(struct grade *head,struct grade *tail)
|
||||
{
|
||||
if(head==NULL)
|
||||
{
|
||||
printf("error!\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct grade *p=head;
|
||||
while(p->next!=NULL)
|
||||
{
|
||||
printgrade1(p);
|
||||
p=p->next;
|
||||
}
|
||||
printgrade1(tail);
|
||||
printf("\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
}
|
||||
void judge(struct grade *head,struct grade *tail,struct grade *next,struct grade *prev,struct grade *pres)
|
||||
{
|
||||
bool judgechar(char str1[],char str2[]);
|
||||
void student2(struct grade *head,struct grade *tail,struct grade *next,struct grade *prev,struct grade *pres);
|
||||
char s[3],s1[10]="yes";
|
||||
printf("countinue?\n");
|
||||
scanf("%s",s);
|
||||
if(judgechar(s,s1))
|
||||
{student2(head,tail,next,prev,pres);
|
||||
return;}
|
||||
else
|
||||
{menu(head,tail);
|
||||
return;}
|
||||
}
|
||||
void fill(struct grade *p)
|
||||
{
|
||||
printf("id: ");
|
||||
scanf("%s",(*p).id);
|
||||
printf("class: ");
|
||||
scanf("%s",(*p).clas);
|
||||
printf("name: ");
|
||||
scanf("%s",(*p).name);
|
||||
printf("score1: ");
|
||||
scanf("%f",&(*p).score1);
|
||||
printf("score2: ");
|
||||
scanf("%f",&(*p).score2);
|
||||
printf("score3: ");
|
||||
scanf("%f",&(*p).score3);
|
||||
p->score=p->score1+p->score2+p->score3;
|
||||
}
|
||||
void student1(struct grade *head)
|
||||
{
|
||||
void student2(struct grade *head,struct grade *tail,struct grade *next,struct grade *prev,struct grade *pres);
|
||||
struct grade *p,*tail;
|
||||
p=(struct grade *)malloc(len);
|
||||
fill(p);
|
||||
p->next=NULL;
|
||||
p->prev=NULL;
|
||||
head=p;
|
||||
tail=p;
|
||||
judge(head,tail,(*p).next,(*p).prev,p);
|
||||
return;
|
||||
}
|
||||
void student2(struct grade *head,struct grade *tail,struct grade *next,struct grade *prev,struct grade *pres)
|
||||
{
|
||||
struct grade *p,*q=pres;
|
||||
p=(struct grade *)malloc(len);
|
||||
fill(p);
|
||||
q->next=p;
|
||||
p->next=NULL;
|
||||
p->prev=q;
|
||||
tail=p;
|
||||
judge(head,tail,next,prev,p);
|
||||
return;
|
||||
}
|
||||
bool judgechar(char str1[],char str2[])
|
||||
{
|
||||
int Len=strlen(str2),i,m=1;
|
||||
for(i=0;i<=Len-1;i++)
|
||||
{
|
||||
if(str1[i]!=str2[i])
|
||||
{
|
||||
m=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(m==1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void delet(struct grade *head,struct grade *tail)
|
||||
{
|
||||
if(head==NULL||head->next==NULL)
|
||||
{
|
||||
printf("error!\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[256],str1[10],str2[10]="yes";
|
||||
struct grade *p=head->next;
|
||||
printf("The student you want to delete: ");
|
||||
scanf("%s",str);
|
||||
if(judgechar(head->id,str)||judgechar(head->name,str))
|
||||
{
|
||||
struct grade *p1;
|
||||
p1=head->next;
|
||||
free(head);
|
||||
head=p1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(judgechar(tail->id,str)||judgechar(tail->name,str))
|
||||
{
|
||||
struct grade *p1;
|
||||
(*(tail->prev)).next=NULL;
|
||||
p1=tail->prev;
|
||||
free(tail);
|
||||
tail=p1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(p->next!=NULL)
|
||||
{
|
||||
if(judgechar(p->id,str)||judgechar(p->name,str))
|
||||
{
|
||||
(*(p->prev)).next=p->next;
|
||||
(*(p->next)).prev=p->prev;
|
||||
free(p);
|
||||
break;
|
||||
}
|
||||
else
|
||||
p=p->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Do you want to delete anymore?\n");
|
||||
scanf("%s",str1);
|
||||
if(judgechar(str1,str2))
|
||||
{
|
||||
if(head->next==NULL)
|
||||
{
|
||||
printf("error!\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
delet(head,tail);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printgrade(head,tail);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void swap1(char str1[],char str2[])
|
||||
{
|
||||
char str[100];
|
||||
strcpy(str,str2);
|
||||
strcpy(str2,str1);
|
||||
strcpy(str1,str);
|
||||
}
|
||||
void swap(struct grade *p,struct grade *q)
|
||||
{
|
||||
int temp;
|
||||
swap1(p->id,q->id);
|
||||
swap1(p->name,q->name);
|
||||
swap1(p->clas,q->clas);
|
||||
temp=q->score1;
|
||||
q->score1=p->score1;
|
||||
p->score1=temp;
|
||||
temp=q->score2;
|
||||
q->score2=p->score2;
|
||||
p->score2=temp;
|
||||
temp=q->score3;
|
||||
q->score3=p->score3;
|
||||
p->score3=temp;
|
||||
temp=q->score;
|
||||
q->score=p->score;
|
||||
p->score=temp;
|
||||
}
|
||||
void arra(struct grade *head,struct grade *tail)
|
||||
{
|
||||
struct grade *p,*q;
|
||||
if(head==NULL)
|
||||
{
|
||||
printf("error!\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(p=head;p->next!=NULL;p=p->next)
|
||||
{
|
||||
if(p->next==tail)
|
||||
{
|
||||
if(tail->score>p->score)
|
||||
swap(p,tail);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(q=p->next;q->next!=NULL;q=q->next)
|
||||
{
|
||||
if(q->score>p->score)
|
||||
swap(p,q);
|
||||
}
|
||||
if(tail->score>p->score)
|
||||
swap(p,tail);
|
||||
}
|
||||
}
|
||||
printgrade(head,tail);
|
||||
return;
|
||||
}
|
||||
}
|
||||
void selecty(struct grade *head,struct grade *tail)
|
||||
{
|
||||
struct grade *p;
|
||||
char str[100];
|
||||
int m=0;
|
||||
if(head==NULL)
|
||||
{
|
||||
printf("error!\n");
|
||||
menu(head,tail);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Who do you want to inquire: ");
|
||||
scanf("%s",str);
|
||||
for(p=head;p->next!=NULL;p=p->next)
|
||||
{
|
||||
if(judgechar(p->id,str)||judgechar(p->name,str))
|
||||
{
|
||||
printgrade1(p);
|
||||
m++;
|
||||
menu(head,tail);
|
||||
}
|
||||
}
|
||||
if(judgechar(tail->id,str)||judgechar(tail->name,str))
|
||||
{
|
||||
printgrade1(tail);
|
||||
m++;
|
||||
menu(head,tail);
|
||||
}
|
||||
if(m==0)
|
||||
printf("there is no eligible student\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{ struct grade *head=NULL,*tail;
|
||||
menu(head,tail);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue