刚刚做完的一个课题作业,虽然还有些不够完善但已经足够用啦
#include
#include
#include
#include
#include
#include
#include
#define LEN sizeof(struct student)
struct student
{
char name[10];
int num;
float k1;
float k2;
float k3;
float k4;
float k5;
float k6;
int mc;
float ave_score;
float sum_score;
struct student *next;
};
int n_1 = 0;
int n_2 = 0;
char f_name[20];
int flag_creat = 0;
struct student *creat_file(); //从文件录入;
void print(struct student *head); //输出链表;
struct student *del(struct student *head); //删除结点;
struct student *add(struct student *head); //添加数据;
struct student *InsertSort(struct student *head); // 排序
struct student *InsertSort1(struct student *head); //从高到低排序;
struct student *InsertSort2(struct student *head); //从低到高排序;
struct student *InsertSort3(struct student *head); //按学号排序;
struct student *InsertSort4(struct student *head); //字典序;
void refer(struct student *head); //查询
void refer1(struct student *head); //按学号查询排名、成绩;
void refer2(struct student *head); // 按姓名查询;
void cal_ave_s(struct student *head); //计算每个学生的总分和平均分;
void cal_ave_c(struct student *head); //计算每门课程的总分和平均分;
void category(struct student*head);
struct student *del(struct student *head); //信息删除
void prit_file( struct student*head ); //写入文件
void change(struct student *head); // 信息更改
int main()
{
struct student *stu;
stu = (struct student *)(malloc(LEN));
/*录入学生信息 */
int flag_c;
printf("\n\n\n\n\n\n");
printf(" ****************************************\n");
printf(" * 录入学生信息 *\n");
printf(" ****************************************\n\n\n\n\n\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 1. 从文件批量录入学生信息 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 2. 手动录入学生信息 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 0. 退出程序 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '2'))
{
flag_c = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n"); //提高了容错率
a_1 = 1;
}
}
/* 用switch语句 结构清晰*/
switch(flag_c)
{
case 1:{system("cls");
printf(" ****************************************************************\n");
printf(" * 从文件批量录入学生信息 *\n");
printf(" ****************************************************************\n");
stu = creat_file();
break;
}
case 2:{stu = NULL;
char hc[20];
struct student *p_1;
p_1 = (struct student *)(malloc(LEN));
system("cls");
printf(" *********************************************************\n");
printf(" * 手动录入学生信息 *\n");
printf(" **********************************************************\n");
printf("\n\n提示:开始录入数据!\n\n");
stu = add(stu);
FILE *ch;
printf("\n\n请输入数据保存路径:");
scanf("%s",f_name);
ch = fopen(f_name,"w+");
p_1 = stu;
while( p_1!=NULL )
{
fprintf(ch," %d %s %f %f %f %f %f %f",p_1->num,p_1->name,p_1->k1,p_1->k2,p_1->k3,p_1->k4,p_1->k5,p_1->k6);
if(p_1->next != NULL)
{
fprintf(ch,"\n");
}
p_1 = p_1->next;
}
system("pause");
};break;
case 0:printf("\n\n您将退出,");system("pause");exit(0);
}
if(flag_creat == 1)
{
printf("\n\n您将退出,");
system("pause");
}
else
{
printf("\n\n您将进入学生信息管理系统,");
system("pause");
int choice;
for( ; ; )
{
system("cls");
printf(" ************************************\n");
printf(" * 欢迎使用学生信息管理系统 V3.0 *\n");
printf(" ************************************\n\n\n\n\n\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 1. 增量式录入学生信息 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 2. 计算每门课程的总分和平均分 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 3. 查看成绩表 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 4. 查询学生信息 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 5. 各科成绩分析 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 6. 输出学生全部信息 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 7. 将每个学生的个人信息和成绩写入文件 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 8. 学生信息删除 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 9. 学生信息更改 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 0. Exit |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '9'))
{
choice = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(choice)
{
case 1: {
struct student *p_2;
p_2 = (struct student *)(malloc(LEN));
system("cls");
printf(" ****************************************\n");
printf(" * 增量式手动录入学生数据 *\n");
printf(" ****************************************\n\n");
printf("\n\n提示:开始录入数据!\n\n");
stu = add(stu);
FILE *p_add;
p_add = fopen(f_name,"w");
p_2 = stu;
while( p_2!=NULL )
{
fprintf(p_add," %d %s %f %f %f %f %f %f",p_2->num,p_2->name,p_2->k1,p_2->k2,p_2->k3,p_2->k4,p_2->k5,p_2->k6);
if(p_2->next != NULL)
{
fprintf(p_add,"\n");
}
p_2 = p_2->next;
}
system("pause");
break;
};
case 2:{
system("cls");
cal_ave_c(stu);
printf("\n\n您将返回主菜单,");
system("pause");
break;
};
case 3:stu = InsertSort(stu);break;
case 4:stu = InsertSort1(stu);refer(stu);break;
case 5:system("cls");category(stu);break;
case 6:stu = InsertSort1(stu);stu = InsertSort3(stu);print(stu);system("pause");break;
case 7:stu = InsertSort1(stu);system("cls");prit_file(stu );break;
case 8:{
struct student *p_2;
p_2 = (struct student *)(malloc(LEN));
system("cls");
stu = del(stu);
system("pause");
FILE *p_del;
p_del = fopen(f_name,"w");
p_2 = stu;
while( p_2!=NULL )
{
fprintf(p_del," %d %s %f %f %f %f %f %f",p_2->num,p_2->name,p_2->k1,p_2->k2,p_2->k3,p_2->k4,p_2->k5,p_2->k6);
if(p_2->next != NULL)
{
fprintf(p_del,"\n");
}
p_2 = p_2->next;
}
break;
}
case 9:system("cls");change(stu);system("pause");break;
case 0:printf("\n\n");system("pause"); printf("\n\n谢谢使用!\n\n");exit(0);
default:{
printf("\n\n提示:选项不存在请重新输入!\n\n");
system("pause");
};
}
}
}
return 0;
}
void change(struct student *head)
{
struct student *p_ch;
p_ch = (struct student *)malloc(LEN);
struct student *p_ch1;
p_ch1 = (struct student *)malloc(LEN);
printf(" ******************************************************************\n");
printf(" * 更改学生数据 *\n");
printf(" ******************************************************************\n\n\n");
FILE*z;
z=fopen( f_name,"w" );
int i = 1;
int flag = 1;
int flag_d = 1;
int flag_s = 1;
int n;
int n_ch;
for(;flag;)
{
p_ch = head;
p_ch1 = head;
flag_s = 1;
flag_d = 1;
printf("\n\n\n请输入要更改数据的学号:");
scanf("%d", &n_ch);
printf("\n\n");
while(p_ch1!=NULL)
{
if(p_ch1->num == n_ch){ break; }
else{ p_ch1=p_ch1->next; }
}
if(p_ch1==NULL)
{
printf("\n\n系统没有查到改学生的数据,请您查阅是否有输入该学生的数据,谢谢合作\n");
}
else
{
printf("\n\n该学生信息:");
printf("\n\n学号 \t姓名 总成绩\tk1\tk2\tk3\tk4\tk5\tk6\n");
printf("%d\t%s",p_ch1->num, p_ch1->name);
int mm;
for(mm=1;mm<=10-strlen(p_ch1->name);mm++)
{
printf(" ");
}
printf(" ");
printf(" %.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n\n",p_ch1->sum_score,p_ch1->k1 ,p_ch1->k2 ,p_ch1->k3 ,p_ch1->k4 ,p_ch1->k5 ,p_ch1->k6);
printf("\n\n请选择要更改的数据:\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 1. 更改学生姓名 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 2. 更改k1 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 3. 更改k2 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 4. 更改k3 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 5. 更改k4 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 6. 更改k5 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 7. 更改k6 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 8. 更改全部成绩 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 0. 返回主菜单 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n\n\n");
for( ; flag_s; )
{
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '8'))
{
n = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(n)
{
case 1:{
printf("\n\n请输入新的学生姓名: ");
char s[10];
char*x1,*x2;
scanf("%s",s);
int i;
for(i=0;i<=9;i++)
{
p_ch1->name[i]='\0';
}
x1=&p_ch1->name[0] ;
x2=&s[0];
strcpy(x1,x2);
flag_s = 0;
break;
};
case 2:{
printf("\n\n请输入新的k1成绩: ");
float k1_ch;
scanf("%f",&k1_ch);
p_ch1->k1 = k1_ch;
flag_s = 0;
break;
};
case 3:{
printf("\n\n请输入新的k2成绩: ");
float k2_ch;
scanf("%f",&k2_ch);
p_ch1->k2 = k2_ch;
flag_s = 0;
break;
};
case 4:{
printf("\n\n请输入新的k3成绩: ");
float k3_ch;
scanf("%f",&k3_ch);
p_ch1->k3 = k3_ch;
flag_s = 0;
break;
};
case 5:{
printf("\n\n请输入新的k4成绩: ");
float k4_ch;
scanf("%f",&k4_ch);
p_ch1->k4 = k4_ch;
flag_s = 0;
break;
};
case 6:{
printf("\n\n请输入新的k5成绩: ");
float k5_ch;
scanf("%f",&k5_ch);
p_ch1->k5 = k5_ch;
flag_s = 0;
break;
};
case 7:{
printf("\n\n请输入新的k6成绩: ");
float k6_ch;
scanf("%f",&k6_ch);
p_ch1->k6 = k6_ch;break;
flag_s = 0;
};
case 8:{
float n_1;
float n_2;
float n_3;
float n_4;
float n_5;
float n_6;
printf("\n\n请输入新的k1成绩: ");
scanf("%f", &n_1);
printf("\n请输入新的k2成绩: ");
scanf("%f",&n_2);
printf("\n请输入新的k3成绩: ");
scanf("%f",&n_3);
printf("\n请输入新的k4成绩: ");
scanf("%f",&n_4);
printf("\n请输入新的k5成绩: ");
scanf("%f",&n_5);
printf("\n请输入新的k6成绩: ");
scanf("%f", &n_6);
p_ch1->k1 = n_1;
p_ch1->k2 = n_2;
p_ch1->k3 = n_3;
p_ch1->k4 = n_4;
p_ch1->k5 = n_5;
p_ch1->k6 = n_6;
flag_s = 0;
break;
};
case 0: flag_d = 0;flag_s = 0;flag = 0;printf("\n\n您将返回主菜单,");break;
default:printf("\n\n选择错误,请重新选择!\n");
}
}
while( p_ch!=NULL )
{
fprintf(z,"%d %s %.1f %.1f %.1f %.1f %.1f %.1f",p_ch->num,p_ch->name,p_ch->k1,p_ch->k2,p_ch->k3,p_ch->k4,p_ch->k5,p_ch->k6);
if(p_ch->next != NULL)
{
fprintf(z,"\n");
}
p_ch = p_ch->next;
}
rewind(z);
}
if(flag_d)
{
printf("\n\n数据更改完成!");
flag_d = 1;
for( ; flag_d; )
{
printf("\n\n");
printf(" |------------------------------------|\n");
printf(" | 是否继续更改? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(flag)
{
case 1:{
flag_d = 0;
break;
};
case 0:{
printf("\n\n您将返回主菜单,");
flag_d = 0;
flag = 0;
break;
};
}
}
}
flag_d = 1;
}
fclose(z);
}
struct student *creat_file()
{
printf("\n\n请输入数据来源文件路径(默认路径请输入e:\\\\学生信息.txt,若从其他文件录入,请输入其它路径):");
scanf("%s",f_name);
getchar();
FILE*fp;
if((fp=fopen(f_name,"r")) == NULL)
{
printf("\n\n路径错误,请选择:\n\n");
printf(" |------------------------------------|\n");
printf(" | 是否重新输入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
int n;
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
n = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
struct student*ppp;
if(n==1){ ppp=creat_file();return ppp; }
else
{
flag_creat = 1;
return NULL;
}
}
else
{
printf("\n\n\n提示:正在录入数据......");
struct student *head;
struct student *p1,*p2;
n_1=1;
head = p1 = p2 =(struct student*)malloc(LEN);
fscanf(fp,"%ld %s %f %f %f %f %f %f",&p1->num,p1->name,&p1->k1,&p1->k2,&p1->k3,&p1->k4,&p1->k5,&p1->k6);
p1->sum_score = (p1->k1 + p1->k2 + p1->k3 + p1->k4 + p1->k5 + p1->k6);
p1->ave_score = (p1->k1 + p1->k2 + p1->k3 + p1->k4 + p1->k5 + p1->k6)/6;
head=NULL;
if(p1->name==0) {return(head);}
while(!feof(fp))
{
n_1=n_1+1;
if(n_1==2){ head=p1; }
p2=(struct student*)malloc(LEN);
fscanf(fp,"%ld",&p2->num );
fscanf(fp,"%s" ,p2->name );
fscanf(fp,"%f",&p2->k1 );
fscanf(fp,"%f",&p2->k2 );
fscanf(fp,"%f",&p2->k3 );
fscanf(fp,"%f",&p2->k4 );
fscanf(fp,"%f",&p2->k5 );
fscanf(fp,"%f",&p2->k6 );
p1->next=p2;
p1=p2;
p1->sum_score = p1->k1 + p1->k2 + p1->k3 + p1->k4 + p1->k5 + p1->k6;
p1->ave_score = (p1->k1 + p1->k2 + p1->k3 + p1->k4 + p1->k5 + p1->k6)/6.0;
}
p1->next=NULL;
printf("\n\n\n\n提醒:录入完毕,共录入%d个数据\n\n\n",n_1);
if(fclose(fp)==0){ printf("文件成功关闭\n\n"); }
return(head);
}
}
struct student *add(struct student *head)
{
struct student *p_add, *p1, *p2;
p_add = (struct student *)malloc(LEN);
p1 = p2 = (struct student *)malloc(LEN);
p2 = head;
int flag_p2 = 0;
char num_add[8];
int i_add;
int num_a[8];
int flag_add = 1;
int i_f;
int choice = 1;
for(;choice == 1;)
{
if(head == NULL)
{
flag_add = 1;
for( ; flag_add; )
{
printf("请输入八位学号:");
fflush(stdin);
int jt;
for(jt=0;jt<=7;jt++){ num_add[jt]='\0'; }
scanf("%s", num_add);
for(i_add = 0; i_add < 8; i_add++)
{
if((num_add[i_add] >= '0') && (num_add[i_add] <= '9'))
{
num_a[i_add] = (int)num_add[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->num = 0;int hh;
for( i_f = 0,hh=7; i_f <= 7; i_f++,hh--)
{
p_add->num = p_add->num + num_a[i_f] * pow(10 , hh);
}
printf("\n请输入姓名:");
scanf("%s", p_add->name);
int zz,nnn=0; //更改;
int flag0=1;
for(zz=0;zz<=strlen(p_add->name)-1;zz++)
{
if( (p_add->name[zz]<='z'&&p_add->name[zz]>='a')|| (p_add->name[zz]<='Z'&&p_add->name[zz]>='A') ){nnn++;}
else{ break; }
}
if( nnn==(strlen(p_add->name))&&(( p_add->name[zz-1]<='z'&&p_add->name[zz-1]>='a')|| (p_add->name[zz-1]<='Z'&&p_add->name[zz-1]>='A' ) ) ) { flag0=0; }
else
{
printf("\n\n输入错误!\n");
printf(" |------------------------------------|\n");
printf(" | 是否重新输入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag0 = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
if(flag0==0)
{
return head;
}
}
while(flag0)
{
nnn=0;
for(zz=0;zz<=9;zz++)
{
p_add->name[zz]='\0';
}
printf("\n请输入姓名:");
scanf("%s", p_add->name);
for(zz=0;zz<=strlen(p_add->name)-1;zz++)
{
if( (p_add->name[zz]<='z'&&p_add->name[zz]>='a')|| (p_add->name[zz]<='Z'&&p_add->name[zz]>='A') ){nnn++;}
else{break; }
}
if(nnn==strlen(p_add->name) ) { flag0=0; }
else
{
printf("\n\n输入错误\n");
printf(" |------------------------------------|\n");
printf(" | 是否继续录入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '1') && (a1 <= '2'))
{
flag0 = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
if(flag0==0)
{
return head;
}
}
}
flag_add = 1;
char add_k1[9];
int ad_1[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k1:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k1[jt]='\0'; }
scanf("%s", add_k1);
int r;
r=strlen(add_k1);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k1[i_add] >= '0') && (add_k1[i_add] <= '9'))
{
ad_1[i_add] = (int)add_k1[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k1 = 0;
for( i_f = 0,hh=strlen(add_k1)-1; i_f <=strlen(add_k1)-1; i_f++,hh--)
{
p_add->k1 = p_add->k1 + ad_1[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k2[9];
int ad_2[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k2:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k2[jt]='\0'; }
scanf("%s", add_k2);
int r;
r=strlen(add_k2);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k2[i_add] >= '0') && (add_k2[i_add] <= '9'))
{
ad_2[i_add] = (int)add_k2[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k2 = 0;
for( i_f = 0,hh=strlen(add_k2)-1; i_f <=strlen(add_k2)-1; i_f++,hh--)
{
p_add->k2 = p_add->k2 + ad_2[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k3[9];
int ad_3[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k3:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k3[jt]='\0'; }
scanf("%s", add_k3);
int r;
r=strlen(add_k3);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k3[i_add] >= '0') && (add_k3[i_add] <= '9'))
{
ad_3[i_add] = (int)add_k3[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k3 = 0;
for( i_f = 0,hh=strlen(add_k3)-1; i_f <=strlen(add_k3)-1; i_f++,hh--)
{
p_add->k3 = p_add->k3 +ad_3[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k4[9];
int ad_4[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k4:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k4[jt]='\0'; }
scanf("%s", add_k4);
int r;
r=strlen(add_k4);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k4[i_add] >= '0') && (add_k4[i_add] <= '9'))
{
ad_4[i_add] = (int)add_k4[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k4 = 0;
for( i_f = 0,hh=strlen(add_k4)-1; i_f <=strlen(add_k4)-1; i_f++,hh--)
{
p_add->k4 = p_add->k4 + ad_4[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k5[9];
int ad_5[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k5:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k5[jt]='\0'; }
scanf("%s", add_k5);
int r;
r=strlen(add_k5);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k5[i_add] >= '0') && (add_k5[i_add] <= '9'))
{
ad_5[i_add] = (int)add_k5[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k5 = 0;
for( i_f = 0,hh=strlen(add_k5)-1; i_f <=strlen(add_k5)-1; i_f++,hh--)
{
p_add->k5 = p_add->k5 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k6[9];
int ad_6[9]={0};
for( ; flag_add; )
{
printf("\n\n请输入k6:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k6[jt]='\0'; }
scanf("%s", add_k6);
int r;
r=strlen(add_k6);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k6[i_add] >= '0') && (add_k6[i_add] <= '9'))
{
ad_6[i_add] = (int)add_k6[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k6 = 0;
for( i_f = 0,hh=strlen(add_k6)-1; i_f <=strlen(add_k6)-1; i_f++,hh--)
{
p_add->k6 = p_add->k6 + ad_6[i_f] * pow(10 , hh);
}
p_add->sum_score = (p_add->k1 + p_add->k2 + p_add->k3 + p_add->k4 + p_add->k5 + p_add->k6);
p_add->ave_score = (p_add->k1 + p_add->k2 + p_add->k3 + p_add->k4 + p_add->k5 + p_add->k6)/6.0;
n_2++;
head = p_add;
head->next = NULL;
printf(" |------------------------------------|\n");
printf(" | 是否继续录入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
choice = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
}
else
{
p_add = (struct student *)malloc(LEN);
while(choice == 1)
{
flag_add = 1;
flag_p2 = 0;
p2 = head;
p1 = head;
for(;p1->next != NULL;)
{
p1 = p1->next;
}
p2 = head;
printf("\n");
printf("\n\n请输入学号:");
for( ; flag_add; )
{
fflush(stdin);
int jt;
for(jt=0;jt<=7;jt++){ num_add[jt]='\0'; }
scanf("%s", num_add);
for(i_add = 0; i_add < 8; i_add++)
{
if((num_add[i_add] >= '0') && (num_add[i_add] <= '9'))
{
num_a[i_add] = (int)num_add[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->num = 0;int hh;
for( i_f = 0,hh=7; i_f <= 7; i_f++,hh--)
{
p_add->num = p_add->num + num_a[i_f] * pow(10 , hh);
}
while(p2!=NULL)
{
if(p_add->num == p2->num )
{
if(p_add != p2 )
{
flag_p2 = 1;
printf("\n\n与已存在学生学号重复,请重新输入!\n\n");
break;
}
}
p2 = p2->next;
}
if(flag_p2 == 0)
{
printf("\n请输入姓名:");
scanf("%s", p_add->name);
int zz,nnn=0; //更改;
int flag0=1;
for(zz=0;zz<=strlen(p_add->name)-1;zz++)
{
if( (p_add->name[zz]<='z'&&p_add->name[zz]>='a')|| (p_add->name[zz]<='Z'&&p_add->name[zz]>='A') ){nnn++;}
else{ break; }
}
if( nnn==(strlen(p_add->name))&&(( p_add->name[zz-1]<='z'&&p_add->name[zz-1]>='a')|| (p_add->name[zz-1]<='Z'&&p_add->name[zz-1]>='A' ) ) ) { flag0=0; }
else
{
printf("\n\n输入错误!\n");
printf(" |------------------------------------|\n");
printf(" | 是否重新输入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag0 = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
if(flag0==0){return head; }
}
while(flag0)
{
nnn=0;
for(zz=0;zz<=9;zz++)
{
p_add->name[zz]='\0';
}
printf("\n请输入姓名:");
scanf("%s", p_add->name);
for(zz=0;zz<=strlen(p_add->name)-1;zz++)
{
if( (p_add->name[zz]<='z'&&p_add->name[zz]>='a')|| (p_add->name[zz]<='Z'&&p_add->name[zz]>='A') ){nnn++;}
else{break; }
}
if(nnn==strlen(p_add->name) ) { flag0=0; }
else
{
printf("\n\n输入错误\n");
printf(" |------------------------------------|\n");
printf(" | 是否重新输入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
printf("请输入您的选择:");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag0 = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
if(flag0==0){ return head; }
}
}
flag_add = 1;
char add_k1[9];
int ad_1[9];
for( ; flag_add; )
{
printf("\n\n请输入k1:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k1[jt]='\0'; }
scanf("%s", add_k1);
int r;
r=strlen(add_k1);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k1[i_add] >= '0') && (add_k1[i_add] <= '9'))
{
ad_1[i_add] = (int)add_k1[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k1 = 0;
for( i_f = 0,hh=strlen(add_k1)-1; i_f <=strlen(add_k1)-1; i_f++,hh--)
{
p_add->k1 = p_add->k1 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k2[9];
int ad_2[9];
for( ; flag_add; )
{
printf("\n\n请输入k2:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k2[jt]='\0'; }
scanf("%s", add_k2);
int r;
r=strlen(add_k2);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k2[i_add] >= '0') && (add_k2[i_add] <= '9'))
{
ad_2[i_add] = (int)add_k2[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k2 = 0;
for( i_f = 0,hh=strlen(add_k2)-1; i_f <=strlen(add_k2)-1; i_f++,hh--)
{
p_add->k2 = p_add->k2 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k3[9];
int ad_3[9];
for( ; flag_add; )
{
printf("\n\n请输入k3:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k3[jt]='\0'; }
scanf("%s", add_k3);
int r;
r=strlen(add_k3);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k3[i_add] >= '0') && (add_k3[i_add] <= '9'))
{
ad_3[i_add] = (int)add_k3[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k3 = 0;
for( i_f = 0,hh=strlen(add_k3)-1; i_f <=strlen(add_k3)-1; i_f++,hh--)
{
p_add->k3 = p_add->k3 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k4[9];
int ad_4[9];
for( ; flag_add; )
{
printf("\n\n请输入k4:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k4[jt]='\0'; }
scanf("%s", add_k4);
int r;
r=strlen(add_k4);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k4[i_add] >= '0') && (add_k4[i_add] <= '9'))
{
ad_4[i_add] = (int)add_k4[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k4 = 0;
for( i_f = 0,hh=strlen(add_k4)-1; i_f <=strlen(add_k4)-1; i_f++,hh--)
{
p_add->k4 = p_add->k4 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k5[9];
int ad_5[9];
for( ; flag_add; )
{
printf("\n\n请输入k5:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k5[jt]='\0'; }
scanf("%s", add_k5);
int r;
r=strlen(add_k5);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k5[i_add] >= '0') && (add_k5[i_add] <= '9'))
{
ad_5[i_add] = (int)add_k5[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k5 = 0;
for( i_f = 0,hh=strlen(add_k5)-1; i_f <=strlen(add_k5)-1; i_f++,hh--)
{
p_add->k5 = p_add->k5 + num_a[i_f] * pow(10 , hh);
}
flag_add = 1;
char add_k6[9];
int ad_6[9];
for( ; flag_add; )
{
printf("\n\n请输入k6:");
fflush(stdin);
int jt;
for(jt=0;jt<=8;jt++){ add_k6[jt]='\0'; }
scanf("%s", add_k6);
int r;
r=strlen(add_k6);
for(i_add = 0; i_add < r; i_add++)
{
if((add_k6[i_add] >= '0') && (add_k6[i_add] <= '9'))
{
ad_6[i_add] = (int)add_k6[i_add] - 48;
flag_add = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
flag_add = 1;
break;
}
}
}
p_add->k6 = 0;
for( i_f = 0,hh=strlen(add_k6)-1; i_f <=strlen(add_k6)-1; i_f++,hh--) {
p_add->k6 = p_add->k6 + ad_6[i_f] * pow(10 , hh);
}
p_add->sum_score = (p_add->k1 + p_add->k2 + p_add->k3 + p_add->k4 + p_add->k5 + p_add->k6);
p_add->ave_score = (p_add->k1 + p_add->k2 + p_add->k3 + p_add->k4 + p_add->k5 + p_add->k6)/6.0;
n_2++;
p1->next = p_add;
p_add->next = NULL;
printf(" |------------------------------------|\n");
printf(" | 是否继续录入? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
choice = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
}
}
}
}
printf("\n\n添加数据完毕\n\n");
printf("共新录入%d个数据\n\n",n_2);
return head;
}
void print(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf("学号\t\t\t姓名 总成绩\t 平均成绩\t名次\tk1\t k2\t k3\t k4\t k5\t k6\n");
for(; head != NULL; )
{
printf("%d\t\t",head->num );
printf("%s" ,head->name );
int xx;
for(xx=1;xx<=10-strlen(head->name);xx++){ printf(" "); }
printf(" ");
printf("%.1f\t ",head->sum_score);
printf("%.1f\t ",head->ave_score);
printf(" %d\t",head->mc );
printf("%.1f\t",head->k1 );
printf("%.1f\t",head->k2 );
printf("%.1f\t",head->k3 );
printf("%.1f\t",head->k4 );
printf("%.1f\t",head->k5 );
printf("%.1f\n",head->k6 );
head = head->next;
}
}
void refer(struct student *stu)
{
stu = InsertSort1(stu);
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
struct student *p1;
p1 = (struct student *)(malloc(LEN));
p1 = stu;
int i;
int flag = 1;
for( ; flag; )
{
p1 = head;
system("cls");
printf(" ******************************************************************\n");
printf(" * 学生信息查询 *\n");
printf(" ******************************************************************\n\n\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 1. 按学号查询学生排名及其考试成绩 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 2. 按姓名查询学生排名及其考试成绩 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 0. 返回主菜单 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '2'))
{
i = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(i)
{
case 1:{
system("cls");
refer1(head);
system("pause");
break;
};
case 2:{
system("cls");
refer2(head);
system("pause");
break;
};
case 0:{
flag = 0;
printf("\n\n提示:您将返回主菜单,");
break;
};
default:{
printf("\n\n提示:选项不存在请重新输入!\n\n");
system("pause");
};
}
if(flag)
{
printf(" |------------------------------------|\n");
printf(" | 是否继续查询? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
switch(flag)
{
case 1:{
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
break;
};
case 0:{
printf("\n\n提示:您将返回主菜单,");
system("pause");
};
}
}
}
}
void refer1(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf(" **************************************\n");
printf(" * 按学号查询学生排名及考试成绩 *\n");
printf(" **************************************\n\n\n\n");
head = InsertSort1(head);
int number;
int i = 1;
int flag = 0;
printf("请输入学生学号:");
scanf("%d",&number);
do
{
if( number == head->num )
{
flag = 1;
//3个空格
printf("\n\n学号 \t姓名 名次\t总成绩\tk1\tk2\tk3\tk4\tk5\tk6\n");
printf("%d\t%s",head->num, head->name);
int mm;
for(mm=1;mm<=10-strlen(head->name);mm++)
{
printf(" ");
}
printf(" ");
printf(" %d\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n\n",i, head->sum_score,head->k1 ,head->k2 ,head->k3 ,head->k4 ,head->k5 ,head->k6);
}
i++;
head = head->next;
}while(head != NULL);
if(!flag)
{
printf("\n\n无该学生数据!\n\n");
}
}
void refer2(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf(" **************************************\n");
printf(" * 按姓名查询学生排名及考试成绩 *\n");
printf(" **************************************\n\n\n\n");
head = InsertSort1(head);
char name[10];
int i = 1;
int flag = 0;
printf("请输入学生姓名:");
scanf("%s",name);
do
{
if( strcmp(name,head->name ) == 0 )
{
flag = 1;
printf("\n\n学号 \t姓名 名次\t总成绩\tk1\tk2\tk3\tk4\tk5\tk6\n");
printf("%d\t%s",head->num, head->name);
int mm;
for(mm=1;mm<=10-strlen(head->name);mm++)
{
printf(" ");
}
printf(" ");
printf(" %d\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n\n",i, head->sum_score,head->k1 ,head->k2 ,head->k3 ,head->k4 ,head->k5 ,head->k6);
}
i++;
head = head->next;
}while(head != NULL);
if(!flag)
{
printf("\n\n无该学生数据!\n\n");
}
}
void cal_ave_c(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf(" **************************************\n");
printf(" * 计算每门课程的总分和平均分 *\n");
printf(" **************************************\n\n\n\n");
float k_total[6] = {0};
float k_ave[6] = {0};
while(head!=NULL)
{
k_total[0] = k_total[0] + head->k1;
k_total[1] = k_total[1] + head->k2;
k_total[2] = k_total[2] + head->k3;
k_total[3] = k_total[3] + head->k4;
k_total[4] = k_total[4] + head->k5;
k_total[5] = k_total[5] + head->k6;
head = head->next;
}
k_ave[0] = k_total[0]/(n_1+n_2);
k_ave[1] = k_total[1]/(n_1+n_2);
k_ave[2] = k_total[2]/(n_1+n_2);
k_ave[3] = k_total[3]/(n_1+n_2);
k_ave[4] = k_total[4]/(n_1+n_2);
k_ave[5] = k_total[5]/(n_1+n_2);
printf("\n\n各门课程总分及平均分如下所示\n\n");
printf("科目 \tk1\tk2\tk3\tk4\tk5\tk6\n\n");
printf("平均分\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n\n",k_ave[0],k_ave[1],k_ave[2],k_ave[3],k_ave[4],k_ave[5]);
printf("总分 \t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n\n\n",k_total[0],k_total[1],k_total[2],k_total[3],k_total[4],k_total[5]);
}
void cal_ave_s(struct student *stu)
{
printf(" ************************************************\n");
printf(" * 查看学生总分及平均分 *\n");
printf(" ************************************************\n\n\n\n");
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf("姓名\t 学号 总分\t 平均分\n");
while(head!=NULL)
{
printf("%s",head->name);
int xxx;
for(xxx=1;xxx<=10-strlen(head->name);xxx++ ){ printf(" "); }
printf(" ");
printf("%d\t\t%.1f\t %.1f\n",head->num, head->sum_score, head->ave_score);
head = head->next;
}
}
struct student *InsertSort(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
int i;
int flag = 1;
for( ; flag; )
{
system("cls");
printf(" **************************************\n");
printf(" * 查看成绩表 *\n");
printf(" **************************************\n\n\n\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 1. 按每个学生的总分由高到低排出名次表-Sort in descending order by total score of every student |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 2. 按每个学生的总分由低到高排出名次表-Sort in ascending order by total score of every stuednet |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 3. 按学号由小到大排出成绩表-Sort in ascending order by number |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 4. 按姓名的字典顺序排出成绩表-Sort in dictionary order by name |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 5. 查看学生总分及平均分 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n");
printf(" | 0. 返回主菜单 |\n");
printf(" |---------------------------------------------------------------------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '5'))
{
i = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(i)
{
case 1:{
head = InsertSort1(head);
printf("\n\n提示:成绩从高到低排序完成!\n\n");
print(head);
printf("\n\n");
system("pause");
break;
};
case 2:{
head = InsertSort2(head);
printf("\n\n提示:成绩从低到高排序完成!\n\n");
print(head);
printf("\n\n");
system("pause");
break;
};
case 3:{
head = InsertSort3(head);
printf("\n\n提示:按学号排序完成!\n\n");
print(head);
printf("\n\n");
system("pause");
break;
};
case 4:{
head = InsertSort4(head);
printf("\n\n提示:按姓名字典序排序完成!\n\n");
print(head);
printf("\n\n");
system("pause");
break;
};
case 5:{
system("cls");
cal_ave_s(head);
printf("\n\n");
system("pause");
break;
}
case 0:{
flag = 0;
break;
};
default : printf("\n\n提示:选项不存在请重新输入!");system("pause");
}
if(flag)
{
printf(" |------------------------------------|\n");
printf(" | 是否查看其它成绩表? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
}
}
printf("\n\n提示:您将返回主菜单,");
system("pause");
return head;
}
struct student *InsertSort1(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
struct student *first;
struct student *t;
struct student *p;
struct student *q;
first = head->next;
head->next = NULL;
while (first != NULL)
{
for (t = first, q = head; ((q != NULL) && (q->sum_score > t->sum_score )); p = q, q = q->next);
first = first->next;
if (q == head)
{
head = t;
}
else
{
p->next = t;
}
t->next = q;
}
struct student *pmc;
pmc = (struct student *)(malloc(LEN));
pmc = head;
int i_mc = 1;
for(; pmc != NULL; )
{
pmc->mc = i_mc;
pmc = pmc->next;
i_mc++;
}
return head;
}
struct student *InsertSort2(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
struct student *first;
struct student *t;
struct student *p;
struct student *q;
first = head->next;
head->next = NULL;
while (first != NULL)
{
for (t = first, q = head; ((q != NULL) && (q->sum_score < t->sum_score )); p = q, q = q->next);
first = first->next;
if (q == head)
{
head = t;
}
else
{
p->next = t;
}
t->next = q;
}
return head;
}
struct student *InsertSort3(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
struct student *first;
struct student *t;
struct student *p;
struct student *q;
first = head->next;
head->next = NULL;
while (first != NULL)
{
for (t = first, q = head; ((q != NULL) && q->num < t->num ); p = q, q = q->next);
first = first->next;
if (q == head)
{
head = t;
}
else
{
p->next = t;
}
t->next = q;
}
return head;
}
struct student *InsertSort4(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
struct student *first;
struct student *t;
struct student *p;
struct student *q;
first = head->next;
head->next = NULL;
while (first != NULL)
{
for (t = first, q = head; ((q != NULL) && strcmp(q->name, t->name) < 0); p = q, q = q->next);
first = first->next;
if (q == head)
{
head = t;
}
else
{
p->next = t;
}
t->next = q;
}
return head;
}
void category(struct student*head)
{
printf(" **************************************\n");
printf(" * 各科成绩分析 *\n");
printf(" **************************************\n\n\n\n");
struct student*p;
int num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
p=head;
while(p!=NULL)
{
if( (p->k1)<=100&&(p->k1>=90) ){num1++;}
if( (p->k1)<90&&(p->k1>=80) ){num2++;}
if( (p->k1)<80&&(p->k1>=70) ){num3++;}
if( (p->k1)<70&&(p->k1>=60) ){num4++;}
if( (p->k1)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k1的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
p=head;
num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
while(p!=NULL)
{
if( (p->k2)<=100&&(p->k2>=90) ){num1++;}
if( (p->k2)<90&&(p->k2>=80) ){num2++;}
if( (p->k2)<80&&(p->k2>=70) ){num3++;}
if( (p->k2)<70&&(p->k2>=60) ){num4++;}
if( (p->k2)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k2的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
p=head;
num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
while(p!=NULL)
{
if( (p->k3)<=100&&(p->k3>=90) ){num1++;}
if( (p->k3)<90&&(p->k3>=80) ){num2++;}
if( (p->k3)<80&&(p->k3>=70) ){num3++;}
if( (p->k3)<70&&(p->k3>=60) ){num4++;}
if( (p->k3)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k3的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
p=head;
num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
while(p!=NULL)
{
if( (p->k4)<=100&&(p->k4>=90) ){num1++;}
if( (p->k4)<90&&(p->k4>=80) ){num2++;}
if( (p->k4)<80&&(p->k4>=70) ){num3++;}
if( (p->k4)<70&&(p->k4>=60) ){num4++;}
if( (p->k4)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k4的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
p=head;
num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
while(p!=NULL)
{
if( (p->k5)<=100&&(p->k5>=90) ){num1++;}
if( (p->k5)<90&&(p->k5>=80) ){num2++;}
if( (p->k5)<80&&(p->k5>=70) ){num3++;}
if( (p->k5)<70&&(p->k5>=60) ){num4++;}
if( (p->k5)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k5的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
p=head;
num1=0,num2=0,num3=0,num4=0,num5=0,num=0;
while(p!=NULL)
{
if( (p->k6)<=100&&(p->k6>=90) ){num1++;}
if( (p->k6)<90&&(p->k6>=80) ){num2++;}
if( (p->k6)<80&&(p->k6>=70) ){num3++;}
if( (p->k6)<70&&(p->k6>=60) ){num4++;}
if( (p->k6)<60 ){num5++;}
num++;
p=p->next;
}
printf( "k6的分类情况和占比情况如下:\n\n");
printf( "优秀类人数=%d 百分比为%.2f\n\n",num1,(float)num1/(float)(num) );
printf( "良好类人数=%d 百分比为%.2f\n\n",num2,(float)num2/(float)(num) );
printf( "中等类人数=%d 百分比为%.2f\n\n",num3,(float)num3/(float)(num) );
printf( "及格类人数=%d 百分比为%.2f\n\n",num4,(float)num4/(float)(num) );
printf( "不及格类人数=%d 百分比为%.2f\n\n\n\n",num5,(float)num5/(float)(num) );
printf("------------------------------------------------------------------\n\n");
system("pause");
}
void prit_file( struct student*head )
{
int flag_p = 1;
printf(" **************************************\n");
printf(" * 输出学生数据到文件 *\n");
printf(" **************************************\n\n\n\n");
FILE*p;
char wenjian[30];
for(; flag_p == 1; )
{
printf("\n\n请输入您要将学生信息保存到的文件的文件名,按回车键结束:");
scanf("%s",wenjian);
if( ( p=fopen( wenjian,"w" ) )==NULL )
{
printf("\n\n对不起,您打开的文件出现问题,请您重新尝试,");
system("pause");
}
else
{
flag_p = 0;
}
}
struct student*p1;
p1=head;
while( p1!=NULL )
{
fprintf(p,"%d %d %s %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n",p1->mc,p1->num,p1->name,p1->k1,p1->k2,p1->k3,p1->k4,p1->k5,p1->k6,p1->ave_score,p1->sum_score);
if(p1->next != NULL)
{
fprintf(p,"\n");
}
p1=p1->next;
}
printf("\n\n文件已经成功录入文件,共录入%d个数据,", n_1 + n_2);
system("pause");
}
struct student *del(struct student *stu)
{
struct student *head;
head = (struct student *)(malloc(LEN));
head = stu;
printf(" ********************************\n");
printf(" * 学生信息删除 *\n");
printf(" ********************************\n\n\n\n");
int flag_1 = 1;
int flag = 1;
int i;
char s_name[20];
struct student *p1, *p2;
if(head == NULL)
{
printf("\n\n这是个空表列!\n\n");
}
else
{
for(;flag_1;)
{
int n;
p1 = p2 = head;
printf("\n\n0.退出操作\n");
printf("1.按姓名检索\n");
printf("2.按学号检索\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请选择检索方式:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '2'))
{
i = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
switch(i)
{
case 1 : {
printf("\n\n输入要删除数据的姓名:");
scanf("%s",s_name);
for(;p1 != NULL;)
{
if(strcmp(p1->name ,s_name) != 0)
{
p2 = p1;
p1 = p1->next;
}
else
{
flag = 0;
if(p1 == head)
{
head = p1->next;
p1 = p1->next;
}
else
{
p2->next = p1->next;
p1 = p1->next ;
}
printf("\n删除成功!\n");
}
}
if(flag)
{
printf("\n找不到该数据\n");
}
break;
};
case 2 :{
printf("\n\n输入要删除数据的学号:");
scanf("%d",&n);
for(;p1 != NULL;)
{
if(p1->num != n)
{
p2 = p1;
p1 = p1->next;
}
else
{
flag = 0;
if(p1 == head)
{
head = p1->next;
p1 = p1->next;
}
else if(p1->next == NULL)
{
p2->next = NULL;
}
else
{
p2->next = p1->next;
p1 = p1->next ;
}
printf("\n\n删除成功!\n\n");
}
}
if(flag)
{
printf("\n\n找不到该数据\n");
}
};break;
case 0:flag_1=0;break;
default:printf("\n\n选择错误,重新输入!\n\n");
}
if(flag_1)
{
printf(" |------------------------------------|\n");
printf(" | 是否继续删除? |\n");
printf(" |------------------------------------|\n");
printf(" | 是(1) | 否(0) |\n");
printf(" |------------------------------------|\n\n\n");
char a1;
int a_1 = 1;
for(;a_1;)
{
fflush(stdin);
printf("\n\n请输入您的选择:");
a1 = getchar();
if((a1 >= '0') && (a1 <= '1'))
{
flag_1 = (int)a1 - 48;
a_1 = 0;
}
else
{
printf("\n\n输入错误,请重新输入!\n\n");
a_1 = 1;
}
}
}
}
}
return head;
}