📄 student.c
字号:
NoRecord();
}
else
{
while (1)
{
system("cls");
WinSortDate();
GetString(key,1);
switch(key[0])
{
case '1': //按学号升序排
DataInsertionSort(head,SnoAscForm);
SortSelect();
g_sav = 0;
break;
case '2': //按学号降序排
DataInsertionSort(head,SnoDescForm);
SortSelect();
g_sav = 0;
break;
case '3': //按总分升序排
DataInsertionSort(head,TogradeAscForm);
SortSelect();
g_sav = 0;
break;
case '4': //按总分降序排
DataInsertionSort(head,TogradeDescForm);
SortSelect();
g_sav = 0;
break;
case '0':
return;
default:
goxy(2,20);
printf(" You must input the number between 0 - 4!!");
goxy(2,21);
printf("press any ch to continue");
getch();
}
}
}
}
///////////////////////////3.打印学生成绩/////////////////////////
void printreport(struct student *head,int n)
{
if(g_count<=0)
{
NoRecord();
}
else
{
int i,j,k=0,leaf=1,maxleaf;
char str[1];
struct student *node;
struct student *tmp;
node=head->next;
if (n%N==0)
maxleaf=n/N; //最大页数
else
maxleaf=n/N+1; //最大页数
while(1)
{
system("cls");
winstudengrade();
goxy(35,0);
printf("Print Info");
j=7;
for(i=1;i<=N;i++,j++)
{
goxy(1,j);
printf("%-5s%-20s%3d%8.1f%8.1f%5.1f%8.1f",node->sno,node->name,node->age,node->grade[0],node->grade[1],node->grade[2],node->grade[3]);
printf("%10.1f%6.1f%5.1f",node->grade[4],total(node),total(node)/5.0);
if (++k!=n)
node=node->next;
else
break;
}
goxy(2,18);
printf("Press up down left right !");
goxy(66,18);
printf("Leaf Now :%2d",leaf);
goxy(66,19);
printf("Leaf Total:%2d",maxleaf);
goxy(66,20);
printf("Info Total:%2d",n);
goxy(2,19);
printf("Press [1-%d] to go to the leaf,Press ESC to continue",maxleaf);
while(1)
{
str[0]=getch();
if (isdigit(str[0])&&n>N*(str[0]-49)&&(str[0]!=48)) //输入数字键选择第几页
{
node=head->next;
for (i=1;i<=N*(str[0]-49);i++)
{
node=node->next;
}
leaf=str[0]-48;
k=N*(str[0]-49);
break;
}
if (str[0]==27) //ESC退出
return;
if (str[0]<=0)
{
tmp=head;
str[0]=getch();
if (str[0]==72&&leaf!=1) //向上翻页
{
for(i=0;i<=(leaf-2)*N;i++)
{
tmp=tmp->next;
}
node=tmp;
k=(leaf-2)*N;
leaf--;
break;
}
if (str[0]==80&&leaf!=maxleaf) //向下翻页
{
leaf++;
break;
}
if (str[0]==75&&leaf!=1)
{
node=head->next;
k=0;
leaf=1;
break;
}
if (str[0]==77&&leaf!=maxleaf)
{
for (i=0;i<=(maxleaf-1)*N;i++)
{
tmp=tmp->next;
}
node=tmp;
k=(maxleaf-1)*N;
leaf=maxleaf;
break;
}
}
}
}
}
}
void DeleStudent(struct student *key)
{
char str[1];
goxy(10,11);
printf("Search is succeed,do you want to delete this info or revise it?");
goxy(10,13);
printf("Please input a letter Y(y) or N(n) or U(u):");
goxy(2,20);
printf(" ");
while(1)
{
goxy(56,13);
GetString(str,1);
if (str[0]=='Y'||str[0]=='y')
{
deleteinfo(key);
goxy(2,20);
printf("Delete info is succeed,press any char to continue");
getch();
break;
}
else if (str[0]=='N'||str[0]=='n')
return;
else if (str[0]=='U'||str[0]=='u')
{
strcpy(num[g_z],key->sno);
deleteinfo(key);
AddStudentInfo();
goxy(2,20);
printf("Revise Info is Succeed,please press any char to continue");
getch();
return;
}
else
{
goxy(2,20);
printf(" You input error,please input any Y or N,press any ch to continue");
getch();
goxy(2,20);
printf(" ");
goxy(52,14);
printf(" ");
}
}
return;
}
///////////////////////////6.查询学生信息//////////////////////////
void searchstudents()
{
struct student *q[100]={0};
char str[1] ,sno[4]={'\0'};
int i=0;
if(g_count<=0)
{
NoRecord();
}
else
{
while (1)
{
system("cls");
winsearchstudents();
goxy(55,12);
GetString(str,1);
if (str[0]=='1') //按学号查询
{
struct student *key;
key=head->next;
if(key=searchbysno(head))
DeleStudent(key);
else
{
goxy(2,21);
printf("Search is failed,Press any ch to continue");
getch();
}
continue;
}
else if (str[0]=='2') //按姓名查询
{
if (q[0]=searchbyname(head))
{
goxy(2,20);
printf("Search is succeed,do you want to delete the info ?(Y/N):");
while (1)
{
goxy(60,20);
GetString(str,1);
{
goxy(2,20);
printf(" ");
goxy(2,21);
printf(" ");
goxy(2,20);
printf("Please input the student sno: ");
GetString(sno,3);
while(flag[i])
{
if(strcmp(flag[i]->sno,sno)==0)
{
system("cls");
DeleStudent(flag[i]);
break;
}
i++;
}
if(flag[i]==NULL)
{
goxy(2,21);
puts("The sno isn't in here,please input again!");
getch();
}
break;
}
if (str[0]=='N'||str[0]=='n')
break;
else
{
goxy(2,21);
printf("You input error,please input Y(y) or N(n),press any ch to continue");
getch();
goxy(2,21);
printf(" ");
}
}
}
else
{
goxy(2,21);
printf("There is not a note by the student,Press any ch to continue");
getch();
}
continue;
}
else if (str[0]=='0')
return;
else
goxy(2,20);
printf("You input error, please input a number between 0 to 2");
goxy(2,21);
printf("Press any ch to continue");
getch();
}
}
}
///////////////////////////7.统计成绩/////////////////////////
void statgrade()
{
if(g_count<=0)
{
NoRecord();
}
else
{
system("cls");
goxy(1,2);
printf("----------------------------StatAllThree----------------------------");
goxy(8,3);
printf("\tTop3 by Chinese Garde");
goxy(9,5);
printf("Id \tName");
goxy(34,5);
printf("\tAge \t Grade");
StatSubThree(ChineseDescForm,ContrastChigrade,0);
printf("\t\tTop3 by English Garde\n");
StatSubThree(EnglishDescForm,ContrastEnggrade,1);
printf("\t\tTop3 by Math Garde\n");
StatSubThree(MathDescForm,ContrastMatgrade,2);
printf("\t\tTop3 by Physics Garde\n");
StatSubThree(PhysicsDescForm,ContrastPhygrade,3);
printf("\t\tTop3 by Chemistry Garde\n");
StatSubThree(ChemistryDescForm,ContrastChegrade,4);
StatTotThree(TogradeDescForm,ContrastTotgrade);
Average(head,g_count);
printf("Please enter any key to MenuList");
getch();
return;
}
}
////////////////////////////0.退出//////////////////////////
void out()
{
char key[1];
int m;
while(1)
{
system("cls");
goxy(22,9);
printf("Do you want to out of the system");
goxy(22,11);
printf("Please Enter Y(Yes) , N(No)or C(cancel):");
goxy(62,11);
GetString(key,1);
if (key[0]=='Y'||key[0]=='y')
{
if(g_sav == 0)
{
m=Select("The system have some record no save,do you want to save Y(y) or N(n):");
if(m==1)
savefile();
else if(m==-1)
exit(0);
}
else
{
exit(0);
}
}
else if(key[0]=='c'||key[0]=='C')
{
break;
}
else if(key[0]=='N'||key[0]=='n')
{
getch();
return;
}
else
{
goxy(2,20);
printf(" is a error char,please input a char ( Y , N or C)");
goxy(2,21);
printf(" ");
system("pause");
}
}
}
/////////////////////计算总分/////////////////////
float total(struct student *nod)
{
float sum=0;
sum=nod->grade[0]+nod->grade[1]+nod->grade[2]+nod->grade[3]+nod->grade[4];
return sum;
}
///////////////////////排序////////////////////////
void DataInsertionSort(struct student *head,int (*p)()) //插入排序法
{
struct student *b,*c,*w;
w=head->next;
while (w->next!=NULL)
{
w=w->next;
b=head->next;
while (b!=w)
{
if ((*p)(b,w))
{
c=w;
w=w->pre;
c->pre->next=c->next;
if (c->next!=NULL)
c->next->pre=c->pre;
b->pre->next=c;
c->pre=b->pre;
c->next=b;
b->pre=c;
break;
}
else
b=b->next;
}
}
tail=w;
}
//////////////////////学号总分升降序///////////////////
int SnoAscForm(struct student *p,struct student *q) //学号升序
{
return strcmp(p->sno,q->sno)>0;
}
int SnoDescForm(struct student *p,struct student *q) //学号降序
{
return strcmp(p->sno,q->sno)<0;
}
int TogradeAscForm(struct student *p,struct student *q) //总分升序
{
float total1=0,total2=0;
total1+=p->grade[0]+p->grade[1]+p->grade[2]+p->grade[3]+p->grade[4];
total2+=q->grade[0]+q->grade[1]+q->grade[2]+q->grade[3]+q->grade[4];
return total1>total2;
}
int TogradeDescForm(struct student *p,struct student *q) //总分降序
{
float sumP=0,sumQ=0;
sumP+=p->grade[0]+p->grade[1]+p->grade[2]+p->grade[3]+p->grade[4];
sumQ+=q->grade[0]+q->grade[1]+q->grade[2]+q->grade[3]+q->grade[4];
return sumP<sumQ;
}
///////////////////////单科成绩降序////////////////////
int ChineseDescForm(struct student *p,struct student *q)//语文降序
{
return p->grade[0] < q->grade[0];
}
int EnglishDescForm(struct student *p,struct student *q)//英语降序
{
return p->grade[1] < q->grade[1];
}
int MathDescForm(struct student *p,struct student *q) //数学降序
{
return p->grade[2] < q->grade[2];
}
int PhysicsDescForm(struct student *p,struct student *q) //物理降序
{
return p->grade[3] < q->grade[3];
}
int ChemistryDescForm(struct student *p,struct student *q)//化学降序
{
return p->grade[4] < q->grade[4];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -