📄 kaoshi-7.c
字号:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define Null 0
struct stud
{long num;
char name[10];
int score[4];
struct stud *next;
}*head_ptr,*init();
void Enter(),Del(),Insert(),Find(),List(),Output(),Order(),Count(),Top(void),Bot(void);
int Select(void),check1(),check2(),check3();
int k;
void main()
{
int choice,r=0;
char *password="purf",*so,v;
clrscr();
textcolor(GREEN);
Top();
loop: clrscr();
so=getpass("Please Input The Password:_");fflush(stdin);
if(strcmp(password,so)==0)
{ clrscr();
head_ptr=init();
while(1)
{choice=select();
switch(choice)
{case 1:Enter(head_ptr);break;
case 2:List(head_ptr);break;
case 3:Order(head_ptr);List(head_ptr);break;
case 4:Insert(head_ptr);List(head_ptr);break;
case 5:Find(head_ptr);break;
case 6:Del(head_ptr);List(head_ptr);break;
case 7:Count(head_ptr);break;
case 0:printf("\nDo you really want to exit?");
fflush(stdin);
v=getchar(); fflush(stdin);
if(v=='Y'||v=='y'){Bot();exit(0);} break;
}
getch();clrscr();}
}
else
{printf("Invalue password!\n");r++;delay(1000);
if(r>3)
exit(0);
goto loop;
}
}
int select()
{
char c;
int m;
printf("\n\t\t=================================\n\n");
printf("\t\t1.Enter date 2.List date\n\n");
printf("\t\t3.Order date 4.Insert date\n\n");
printf("\t\t5.Find date 6.Delete date\n\n");
printf("\t\t7.Count date 0.Exit\n\n");
printf("\t\t=================================\n");
printf("\t\tPlease input your choice:_");
scanf("%c",&c); fflush(stdin);
do{
m=check2(c);
if(m!=1)
{printf("Input Error,Please Input Again!");
scanf("%c",&c);}}while(m!=1);fflush(stdin);
return(c-'0');
}
/*gets(so);
do
{ fflush(stdin);
m=check2(so);
if(m==-1)
{printf("Input Error,Please Input Again!");
gets(so);}}while(m==-1);fflush(stdin);
return(m);*/
struct stud *init()
{struct stud *new,*head;
new=(struct stud*)malloc(sizeof(struct stud));
new->next=Null;
head=new;
return(head);}
void Top()
{FILE *fp;
fp=fopen("E:\\a\\zh\\1.C","rb");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\t\t"); textcolor(GREEN);
while(!feof(fp)) putchar(fgetc(fp));
fclose(fp);
getch();clrscr();}
void Bot()
{FILE *fp; clrscr();
fp=fopen("E:\\a\\zh\\2.C","rb");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\t\t");
while(!feof(fp)) putchar(fgetc(fp));
fclose(fp);
delay(1000);}
int check1(struct stud *head,long num)
{
struct stud *p=head;
while(p->num!=num&&p->next!=Null)
p=p->next;
if(p->next==Null&&p->num!=num)
return(1);
else if(p->next!=Null)
return(0);
else return(0); }
int check2(char c)
{ int a;
a=c-'0';
/* char *t;
for(i=0;so[i]==' '||so[i]=='\n';i++);
for(j=0;i<=strlen(so);j++,i++)
t[j]=so[i];
t[j]='\0';
a=atoi(t);*/
if(a>-1&&a<8)
return(1);
else return(0);}
int check3(char s[])
{
int i=0;
while(s[i]>='0'&&s[i]<='9'&&s[i]!='\0')
{i++;}
if((s[i]=='\0'&&i==2)||(s[i]=='\0'&&i==1))
return(1);
else if((s[i]=='\0'&&i>2)||s[i]!='\0')
return(0);
if(s[3]=='\0'&&s[0]=='1'&&s[1]=='0'&&s[2]=='0')
return(1);
}
void Enter(struct stud *head)
{
struct stud *p,*new;
int i,j,po;
char s[3][5];float sum;
textcolor(RED);
do{sum=0;p=head;
while(p->next!=Null)
p=p->next;
new=(struct stud*)malloc(sizeof(struct stud));
printf("Enter number:_");
scanf("%ld",&new->num);
if(k==0&&new->num==0)
{printf("The 0 isn't allowed here! Please Input It Again!");
scanf("%ld",&new->num);}
if(k!=0)
{j=check1(head,new->num);
if(j==0)
{printf("Please Input It Again!");
scanf("%ld",&new->num);} }
if(new->num!=0)
{printf("Enter name:_"); fflush(stdin);
gets(new->name);
printf("Enter English/Maths/Computer score:_\n");
printf("\n");
fflush(stdin);
for(i=0;i<3;i++)
{gets(s[i]);fflush(stdin);
do{po=check3(s[i]);
if(po!=1)
{printf("Please Input It Again! It may be too long Or a word exists!");
gets(s[i]);fflush(stdin);}}while(po!=1);
new->score[i]=atoi(s[i]);
sum+=new->score[i];}
new->score[3]=sum/3;
new->next=Null;
p->next=new;k++; fflush(stdin);}}while(new->num!=0); fflush(stdin);}
void Del(struct stud *head)
{int i,slot,n=1; char s[30],c;
struct stud *p=head->next,*q,*h=head;
while(n)
{printf("Enter the number:_");
gets(s);slot=atol(s);
while(p->num!=slot)
p=p->next; if(p==head)
head=p->next;
else{q=p->next;
while(h->next!=p) h=h->next;
h->next=q;} fflush(stdin);
free(p); k--;
printf("Continue?");
c=getchar(); getch();
if(c=='N'||c=='n')
n=0;}}
void Insert(struct stud *head)
{int i,n=1,sum;
char c;
struct stud *p1=head->next,*p2,*new;fflush(stdin);
while(n)
{sum=0;
new=(struct stud*)malloc(sizeof(struct stud));
printf("Enter number:_");
scanf("%ld",&new->num);
if(new->num==0)
{printf("The 0 isn't allowed here! Please Input It Again!");
scanf("%ld",&new->num);} fflush(stdin);
printf("Enter name:_");
gets(new->name);fflush(stdin);
printf("Enter score:_");
for(i=0;i<3;i++)
{scanf("%d",&new->score[i]);
while(new->score[i]<0||new->score[i]>100)
{printf("Please Input It Again!");scanf("%d",&new->score[i]);}
sum+=new->score[i];}
new->score[3]=sum/3;
while(new->score[3]>p1->score[3]&&p1->next!=Null)
{p2=p1;p1=p1->next;}
if(new->score[3]<=p1->score[3])
{if(head->next==p1)
head->next=new;
else p2->next=new;
new->next=p1;}
else {p1->next=new;
new->next=Null;} k++;
printf("Continue?");
getch();
c=getchar();getch();
if(c=='N'||c=='n')
n=0;}
}
void Find(head)
struct stud *head;
{int slot,n=1,top,bot,mid,i=0,j;
char s[30],c;
struct stud *p=head->next,*q1,*h,*q=head->next,*w[50];
for(j=0;j<k;j++)
{w[j]=p;
p=p->next;}
while(i<k)
{ q=head->next;h=head;
do{q1=q->next;
if(q->num>q1->num)
{ while(h->next!=q) h=h->next;
h->next=q1;
q->next=q1->next;
q1->next=q;
}
if(q->next!=Null)
q=q->next;}while(q->next!=Null);
i++;} fflush(stdin);
while(n)
{printf("Enter the number:_");
gets(s);slot=atol(s);
p=head; top=0;bot=k-1;
while(top<=bot)
{mid=(top+bot)/2;
if(w[mid]->num==slot)
{ printf("\n\t==================================================\n");
printf("\t");
Output(w[mid]);
printf("\n\t==================================================\n\n");
return;}
else if(w[mid]->num>slot)
bot=mid-1;
else top=mid+1;}
if(top>bot)
printf("Can't find the number!");
printf("\nContinue?");
c=getchar(); getch();
if(c=='N'||c=='n')
n=0;}
}
void List(head)
struct stud *head;
{struct stud *ptr; textcolor(RED);
ptr=head->next;
printf("\n\tNumber Name English Maths Computer Average\n");
printf("\t==================================================\n\n");
printf("\t");
while(ptr!=Null)
{Output(ptr);
ptr=ptr->next;
}printf("\n\t==================================================\n\n");}
void Output(struct stud *p)
{int i;
printf("%-5ld",p->num);
printf("%6s",p->name);
for(i=0;i<3;i++)
printf("%9d",p->score[i]);
printf("%9.2f",(float)p->score[3]);
printf("\n\t");
}
void Order(struct stud *head)
{struct stud *q,*q1,*h;int i=0;
while(i<k)
{ q=head->next;h=head;
do{q1=q->next;
if(q->score[3]>q1->score[3])
{ while(h->next!=q) h=h->next;
h->next=q1;
q->next=q1->next;
q1->next=q;
}
if(q->next!=Null)
q=q->next;}while(q->next!=Null);
i++;} }
void Count(struct stud *head)
{int a[5]={0,0,0,0,0},i;
struct stud *p;
p=head;
while(p)
{if(p->score[3]>0&&p->score[3]<60)
a[0]++;
if(p->score[3]>=60&&p->score[3]<70)
a[1]++;
if(p->score[3]>=70&&p->score[3]<80)
a[2]++;
if(p->score[3]>=80&&p->score[3]<90)
a[3]++;
if(p->score[3]>=90&&p->score[3]<100)
a[4]++;
p=p->next;} printf("\n The statistics Record \n");
printf("\n\t===================================================================\n");
printf("\tMark pare: 0-59 60-69 70-79 80-89 90-100 \n\n");
printf("\tperson :");
for(i=0;i<5;i++)
printf("%9d",a[i]);
printf("\n\t====================================================================\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -