新一代学生成绩管理系统(C语言版)

来源:互联网 发布:淘宝客微博推广教程 编辑:程序博客网 时间:2024/05/22 10:26
/*新一代学生成绩管理系统(C语言版) 
 *开发者:凌锋LTS 
 *项目完成日期:2017年5月31日
 *代码行数:1280(行)
 *原创作品,谢谢支持 
 */
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
#define LEN sizeof(SS)
#define FINPUT &p1->no,p1->name,p1->sex,&p1->age,&p1->score[0],&p1->score[1],&p1->score[2],&p1->sum
#define HEADTAIL "+-----------------------------------------------------------------------------+\n"
#define CHTITLE "|  学号    |   姓名     |  性别 |  年龄 |  数学   |   英语  |  C语言  |  总分 |\n"
#define ENTITLE "|  N0      |   Name     |  Sex  |  Age  |  Math   | English |   C     |  Sum  |\n"
#define TOOLONG "|----------+------------+-------+-------+---------+---------+---------+-------|\n"
#define FORMAT "| %-9d| %-11s|  %-5s|  %-5d|  %-7d|  %-7d|  %-7d|  %-5d|\n"


typedef struct student
{
int no;
char name[20];
char sex[4];
int age;
int score[3];
int sum;
struct student *next;
}SS;


void welcome();
void menu1();
void menu2();
void load_data();
void print();
void input();
void insert(SS *);
void delete_();
void search();
void modify();
void count();
void order();
void save();
void help();
void color();
void error();
void free_all();
void show(SS *);


SS *head = NULL;  //全局头指针,避免了传指针的麻烦,但似乎也是有缺点的 
int z = 1;      //全局语言控制变量 
int c = 1;      //全局屏幕颜色控制变量 
int total = 0;  //学生总数


int main()
{
int choice;
welcome();
load_data();
color();
z==1?menu1():menu2();
scanf("%d",&choice);
do
{
switch(choice)
{
case 1:input();break;
case 2:print();break;
case 3:delete_();break;
case 4:search();break;
case 5:modify();break;
case 6:count();break;
case 7:order();break;
case 8:save();break;
case 9:help();break;
case 0:exit(0);
default:error();getch();
}
z==1?menu1():menu2();
scanf("%d",&choice);
}while(choice != 0);
return 0;
}


void welcome()
{
printf("\n\n\n\n\n\n\n");
printf("\t\t  +--------------------------------------------+\n");
printf("\t\t  |                                            |\n");
printf("\t\t  |               Welcome to use               |\n");
printf("\t\t  |                                            |\n");
printf("\t\t  |   Students Score Administrate System V1.0  |\n");
printf("\t\t  |                                            |\n");
printf("\t\t  +--------------------------------------------+\n");
printf("\n\n\n\n\t\t\tPlease press any key to continue...\n\n\n");
getch();
}


void menu1()
{
system("cls");
printf("\n\n");
printf("\t\t       Students Score Administrate System V1.0\n\n");
printf("\t\t\t+-------------Mainmenu-------------+\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t|           [1] Input              |\n");
printf("\t\t\t|           [2] Display            |\n");
printf("\t\t\t|           [3] delete             |\n");
printf("\t\t\t|           [4] Search             |\n");
printf("\t\t\t|           [5] Modify             |\n");
printf("\t\t\t|           [6] Count              |\n");
printf("\t\t\t|           [7] Sort               |\n");
printf("\t\t\t|           [8] Save               |\n");
printf("\t\t\t|           [9] Settings           |\n");
printf("\t\t\t|           [0] Quit               |\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t+----------------------------------+\n");
printf("\n\t\t\tPlease input your choice(0-9):");
}


void menu2()
{
system("cls");
printf("\n\n");
printf("\t\t\t        学生成绩管理系统V1.0\n\n");
printf("\t\t\t+--------------主菜单--------------+\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t|         [1] 输入学生成绩         |\n");
printf("\t\t\t|         [2] 展示学生成绩         |\n");
printf("\t\t\t|         [3] 删除学生成绩         |\n");
printf("\t\t\t|         [4] 查找学生成绩         |\n");
printf("\t\t\t|         [5] 修改学生成绩         |\n");
printf("\t\t\t|         [6] 统计学生成绩         |\n");
printf("\t\t\t|         [7] 排序学生成绩         |\n");
printf("\t\t\t|         [8] 保存                 |\n");
printf("\t\t\t|         [9] 设置                 |\n");
printf("\t\t\t|         [0] 退出                 |\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t+----------------------------------+\n");
printf("\n\t 请输入你的选择(0-9):");
}


void error()
{
if(z==1)
printf("\n\t\t     Input error!\n\t\t     Please press any key to continue...\n");
else
printf("\n\t\t     输入错误!\n\t\t     请按任意键继续...\n");
}


void color()
{
switch(c)
{
case 1:system("color 07");break;
case 2:system("color 0a");break;
case 3:system("color 0f");break;
case 4:system("color f0");break;
case 5:system("color a0");break;
case 6:system("color b0");break;
case 7:system("color c0");break;
case 8:system("color d0");break;
case 9:system("color e0");break;
case 10:system("color 1f");break;
case 11:system("color 9f");break;
case 12:system("color ce");break;
default:system("color 07");break;
}
}


void load_data()
{
FILE *fp;
SS *p1,*p2;
fp = fopen("database.txt","r");
if(!fp)
{
if(z==1)
printf("\nCan not open the file!\nPlease press any key to mainmenu...");
else
printf("\n打开文件失败!\n请按任意键进入主菜单...");
getch();
return;
}
fscanf(fp,"%d\n%d\n%d\n",&z,&c,&total);
head = p1 = p2  = (SS *)malloc(LEN);
fscanf(fp,"%d\t%s\t\t%s\t%d\t%d\t%d\t%d\t%d\n",FINPUT);
while(!feof(fp))
{
p1 = (SS *)malloc(LEN);
fscanf(fp,"%d\t%s\t\t%s\t%d\t%d\t%d\t%d\t%d\n",FINPUT);
p2->next = p1;
p2 = p1;
}
p2->next = NULL;
fclose(fp);
}


void input1()
{
char ch;
SS *p;
do
{
system("cls");
printf("--------------------------Enter Student's Information-------------------------\n");
p = (SS *)malloc(LEN);
printf("------>NO:");
scanf("%d",&p->no);
printf("------>Name:");
scanf("%s",p->name);
printf("------>Sex:");
scanf("%s",p->sex);
printf("------>Age:");
scanf("%d",&p->age);
printf("------>Math:");
scanf("%d",&p->score[0]);
printf("------>Englisg:");
scanf("%d",&p->score[1]);
printf("------>C language:");
scanf("%d",&p->score[2]);
p->sum = p->score[0] + p->score[1] + p->score[2];
printf("\nThis student's information:\n");
printf(HEADTAIL);
printf(ENTITLE);
show(p);
printf(HEADTAIL);
insert(p);
printf("\nContinue to input?(Y/N):");
ch = getch();
}while(ch=='y'||ch=='Y');
printf("\nPlease press [Esc] to Mainmenu...\n");
do{
ch = getch();
}while(ch != 27);
}


void input()
{
char ch;
SS *p;
if(z==1)
{
input1();
return;
}
do
{
system("cls");
printf("---------------------------------输入学生成绩---------------------------------\n");
p = (SS*)malloc(LEN);
printf("------>学号:");
scanf("%d",&p->no);
printf("------>姓名:");
scanf("%s",p->name);
printf("------>性别:");
scanf("%s",p->sex);
printf("------>年龄:");
scanf("%d",&p->age);
printf("------>数学:");
scanf("%d",&p->score[0]);
printf("------>英语:");
scanf("%d",&p->score[1]);
printf("------>C语言:");
scanf("%d",&p->score[2]);
p->sum = p->score[0] + p->score[1] + p->score[2];
printf("\n这个学生的信息为:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p);
printf(HEADTAIL);
insert(p);
printf("\n还要继续输入吗?(Y/N):");
ch = getch();
}while(ch=='y'||ch=='Y');
printf("\n请按[Esc]键返回主菜单...\n");
do{
ch = getch();
}while(ch != 27);
}


void print()
{
SS *p;
char ch;
system("cls");
if(z==1)
printf("------------------------------Display Student Score-----------------------------\n");
else
printf("----------------------------------展示学生成绩----------------------------------\n");
if(head==NULL)
{

z==1?printf("no record!\nPlease press any key to Mainmenu...\n"):
printf("没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
printf(HEADTAIL);
z==1?printf(ENTITLE):printf(CHTITLE);
for(p = head; p!=NULL; p = p->next)
{
show(p);
}
printf(HEADTAIL);
z==1?printf("Total: %d\n",total):printf("学生总数:%d\n",total);
z==1?printf("Please press [Esc] return to Mainmenu...\n"):printf("请按[Esc]键返回主菜单...\n");
do{
ch = getch();
}while(ch != 27);
}


void show(SS *p)
{
printf(TOOLONG);
printf(FORMAT,p->no,p->name,p->sex,p->age,p->score[0],p->score[1],p->score[2],p->sum);
}


void insert(SS *stu)
{
SS *p0, *p1, *p2;
p1 = head;
p0 = stu;
if(head == NULL)
{
head = p0;
p0->next = NULL;
}
else
{
while ((p0->no  >  p1->no)&&(p1->next != NULL))
{
p2 = p1;
    p1 = p1->next;
}
if(p0->no  <=  p1->no)
    {
    if(head == p1)
    head = p0;
  else
    p2->next = p0;
    p0->next = p1;
  }
else
  {
    p1->next = p0;
    p0->next = NULL;
  }  
}
total++;
}


void delete_1()
{
int num;
char ch; 
SS *p1, *p2;
system("cls");
printf("-------------------------------------Delete-------------------------------------\n");
if(head == NULL)
{
printf("no record!\nPlease press any key to Mainmenu...\n");
getch();
return; 
}
printf("\nPlease input the No:");
scanf("%d",&num);
p1 = head;
while(p1->no != num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(p1->no == num)
{
printf("\nThis student's information:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
printf("Are you sure to delete this information?(Y/N):");
if(ch == 'Y'||ch == 'y')
{
if(p1 == head)
head = p1->next;
else
p2->next = p1->next;
free(p1);
printf("\nDelete %d Successfully");
total--;
}
}
else
{
printf("Sorry!this student had been not recorded!\nPress any key return to Mainmenu...");
getch();
return;
}
printf("\nPlease press [Esc] to Mainmenu...\n");
do{
ch = getch();
}while(ch != 27);
}


void delete_()
{
int num;
char ch; 
SS *p1, *p2;
if(z==1)
{
delete_1();
return;
}
system("cls");
printf("----------------------------------删除学生成绩----------------------------------\n");
if(head==NULL)
{
printf("没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
printf("\n请输入学生学号:");
scanf("%d",&num);
p1 = head;
while(p1->no != num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(p1->no == num)
{
printf("这个学生的信息为:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
printf("你确定要删除该学生的信息吗?(Y/N)");
ch = getch();
if(ch == 'Y'||ch == 'y')
{
if(p1==head)
head = p1->next;
else
p2->next = p1->next;
free(p1);
printf("\n删除 %d 成功",num);
total--;
}
}
else
{
printf("抱歉!没有此学生的记录!按任意键返回主菜单...\n");
getch();
return;
}
printf("\n按[Esc]退回主菜单...\n");
do{
ch = getch();
}while(ch != 27);
}


void search1()
{
int num;
char ch;
SS *p1;
system("cls");
printf("------------------------------Search Student Score------------------------------\n");
if(head==NULL)
{
printf("no record!\nPlease press any key to Mainmenu...\n");
getch();
return; 
}
do
    {
    system("cls");
printf("------------------------------Search Student Score------------------------------\n");
        printf("\nInput No:");
    scanf("%d",&num);
        p1 = head;
while(p1->no != num && p1->next != NULL)
p1 = p1->next;
if(p1->no == num)
{
printf("\nThis student's information:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
}
else
printf("Sorry!can not found this student!\n");
printf("Please press any key to continue search.\nor press [Esc] return to Mainmenu:");
ch = getch();
    }while(ch != 27);
}


void search()
{
int num;
char ch;
SS *p1;
if(z==1)
{
search1();
return;
}
system("cls");
printf("----------------------------------查找学生成绩----------------------------------\n");
if(head==NULL)
{
printf("没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
do
    {
    system("cls");
printf("----------------------------------查找学生成绩----------------------------------\n");
        printf("\n请输入学生学号:");
scanf("%d",&num);
        p1 = head;
while(p1->no != num && p1->next != NULL)
p1 = p1->next;
if(p1->no == num )
{
printf("这个学生的信息为:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
}
else
printf("抱歉!没有找到该学生!\n");
printf("请按任意键继续查找\n或按[Esc]退回主菜单:");
ch = getch();
    }while(ch != 27);
}


int modify_do1(SS *p)
{
int ch;
    printf("\t\t         Please choose item to change\n");
    printf("\t\t     +----------------------------------+\n");    
    printf("\t\t     |          [1] NO                  |\n");
    printf("\t\t     |          [2] Name                |\n");
printf("\t\t     |          [3] Sex                 |\n");
printf("\t\t     |          [4] Age                 |\n");
printf("\t\t     |          [5] Math score          |\n");
printf("\t\t     |          [6] English score       |\n");
printf("\t\t     |          [7] C language score    |\n");
printf("\t\t     |          [0] Cancel              |\n");
    printf("\t\t     +----------------------------------+\n");
    printf("\nPlease input your choice:");
    scanf("%d",&ch);
    getchar();
    switch(ch)
    {
case 0:
return 0;
    case 1:
printf("New No:");
scanf("%d",&p->no);
break;
case 2:
printf("New Name:");
    scanf("%s",p->name);
        break; 
    case 3:
        printf("New Sex:");
    scanf("%s",p->sex);
        break;
    case 4:
printf("New Age:");
    scanf("%d",&p->age);
        break; 
    case 5:
            printf("New Math score:");
    scanf("%d",&p->score[0]);
            break; 
    case 6:
            printf("New English score:");
    scanf("%d",&p->score[1]);
            break;
        case 7:
            printf("New C language score:");
    scanf("%d",&p->score[2]);
            break;
    default:
            printf("Input error,please press any key return to Mainmenu...");
getch();
return 0; 
            break;
    }
    printf("Modify successfully\n");
    p->sum = p->score[0] + p->score[1] + p->score[2];
    return 1;
}


int modify_do(SS *p)
{
int ch;
    printf("\t\t         请选择您要修改的学生的项目\n");
    printf("\t\t     +----------------------------------+\n");    
    printf("\t\t     |           [1] 学号               |\n");
    printf("\t\t     |           [2] 姓名               |\n");
printf("\t\t     |           [3] 性别               |\n");
printf("\t\t     |           [4] 年龄               |\n");
printf("\t\t     |           [5] 数学成绩           |\n");
printf("\t\t     |           [6] 英语成绩           |\n");
printf("\t\t     |           [7] C语言成绩          |\n");
printf("\t\t     |           [0] 取消               |\n");
    printf("\t\t     +----------------------------------+\n");
    printf("\n请输入您的选择:");
    scanf("%d",&ch);
    getchar();
    switch(ch)
    {
case 0:
return 0;
    case 1:
printf("请输入新学号:");
scanf("%d",&p->no);
break;
case 2:
        printf("请输入新姓名:");
    scanf("%s",p->name);
            break; 
    case 3:
        printf("请输入新性别:");
    scanf("%s",p->sex);
        break;
    case 4:
printf("请输入新年龄:");
    scanf("%d",&p->age);
        break; 
    case 5:
            printf("请输入数学成绩:");
    scanf("%d",&p->score[0]);
            break; 
    case 6:
            printf("请输入英语成绩:");
    scanf("%d",&p->score[1]);
            break;
        case 7:
            printf("请输入C语言成绩:");
    scanf("%d",&p->score[2]);
            break;
    default:
            printf("输入有误,请按任意键后返回主菜单...");
getch();
return 0; 
            break;
    }
    printf("修改成功\n");
    p->sum = p->score[0] + p->score[1] + p->score[2];
    return 1;
}


void modify1()
{
int num;
char ch; 
SS *p1, *p2;
system("cls");
printf("------------------------------Modify Student Score------------------------------\n");
if(head==NULL)
{
printf("no record!\nPlease press any key to Mainmenu...\n");
getch();
return; 
}
printf("Input No:");
scanf("%d",&num);
getch();
p1 = head;
while(p1->no != num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(p1->no == num)
{
do
{
system("cls");
printf("------------------------------Modify Student Score------------------------------\n");
printf("\nThis student's information:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
if(!modify_do1(p1))
return;
else
printf("Press any key to continue to modify\nor press b[Esc] return to Mainmenu");
ch = getch();
}while(ch != 27);
}
else
{
printf("Sorry!this student had been not recorded!\nPlease press any key to Mainmenu...\n");
getch();
return; 
}
}


void modify()
{
int num;
char ch;
SS *p1, *p2;
if(z==1)
{
modify1();
return;
}
system("cls");
printf("----------------------------------修改学生成绩----------------------------------\n");
if(head==NULL)
{
printf("没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
printf("请输入学生学号:");
scanf("%d",&num);
p1 = head;
while(p1->no != num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(p1->no == num)
{
do
{
system("cls");
printf("----------------------------------修改学生成绩----------------------------------\n");
printf("这个学生的信息为:\n");
printf(HEADTAIL);
printf(CHTITLE);
show(p1);
printf(HEADTAIL);
if(!modify_do(p1))
return;
else
printf("请按任意键继续修改\n或按[Esc]退回主菜单");
ch = getch();
}while(ch != 27);
}
else
{
printf("抱歉!没有此学生的记录!请按任意键返回主菜单...\n");
getch();
return; 
}
}


void count()
{
SS *p,*pma,*pen,*pcl,*pmax;
char ch;
float average;
int ma[5] = {0};
int en[5] = {0};
int cl[5] = {0};
int total_all = 0;
system("cls");
z==1?printf("-------------------------------Count Student Score------------------------------\n"):
printf("----------------------------------统计学生成绩----------------------------------\n");
if(head==NULL)
{
z==1?printf("no record!\nPlease press any key to Mainmenu...\n"):
printf("没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
pmax = pma = pen = pcl = p = head;
for(p = head; p!=NULL; p = p->next)
{

if(p->score[0] < 60) ma[0]++;
if(p->score[1] < 60) en[0]++;
if(p->score[2] < 60) cl[0]++;

if(p->score[0] >= 60 && p->score[0] < 70) ma[1]++;
if(p->score[1] >= 60 && p->score[1] < 70) en[1]++;
if(p->score[2] >= 60 && p->score[2] < 70) cl[1]++;

if(p->score[0] >= 70 && p->score[0] < 80) ma[2]++;
if(p->score[1] >= 70 && p->score[1] < 80) en[2]++;
if(p->score[2] >= 70 && p->score[2] < 80) cl[2]++;

if(p->score[0] >= 80 && p->score[0] < 90) ma[3]++;
if(p->score[1] >= 80 && p->score[1] < 90) en[3]++;
if(p->score[2] >= 80 && p->score[2] < 90) cl[3]++;

if(p->score[0] >= 90 && p->score[0] < 100) ma[4]++;
if(p->score[1] >= 90 && p->score[1] < 100) en[4]++;
if(p->score[2] >= 90 && p->score[2] < 100) cl[4]++;

if(p->score[0] >= pma->score[0]) pma = p;
if(p->score[1] >= pen->score[1]) pen = p;
if(p->score[2] >= pcl->score[2]) pcl = p;

if(p->sum > pmax->sum) pmax = p;
total_all += p->sum;
}
average = (float)total_all/total;
if(z==1)
{
printf("-------------------------------------------------------------------------------\n");
printf("Math          0 ~ 59:%5d (ren)\n",ma[0]);
printf("Math         60 ~ 69:%5d (ren)\n",ma[1]);
printf("Math         70 ~ 79:%5d (ren)\n",ma[2]);
printf("Math         80 ~ 89:%5d (ren)\n",ma[3]);
printf("Math        90 ~ 100:%5d (ren)\n",ma[4]);
printf("-------------------------------------------------------------------------------\n");
printf("English       0 ~ 59:%5d (ren)\n",en[0]);
printf("English      60 ~ 69:%5d (ren)\n",en[1]);
printf("English      70 ~ 79:%5d (ren)\n",en[2]);
printf("English      80 ~ 89:%5d (ren)\n",en[3]);
printf("English     90 ~ 100:%5d (ren)\n",en[4]);
printf("-------------------------------------------------------------------------------\n");
printf("C language    0 ~ 59:%5d (ren)\n",cl[0]);
printf("C language   60 ~ 69:%5d (ren)\n",cl[1]);
printf("C language   70 ~ 79:%5d (ren)\n",cl[2]);
printf("C language   80 ~ 89:%5d (ren)\n",cl[3]);
printf("C language  90 ~ 100:%5d (ren)\n",cl[4]);
printf("--------------------------------------------------------------------------------");
printf("The hightest student by Math       score : NO:%-8dscore :%-5d\n",pma->no,pma->score[0]);
printf("The hightest student by Englisg    score : NO:%-8dscore :%-5d\n",pen->no,pen->score[1]);
printf("The hightest student by C language score :NO:%-8dscore :%-5d\n",pcl->no,pcl->score[2]);
printf("The hightest student by total      score : NO:%-8dscore :%-5d\n",pmax->no,pmax->sum);
printf("-------------------------------------------------------------------------------\n");
printf("Student total :%5d(ren)\nAverage of all student :%.2f\n",total,average);
printf("-------------------------------------------------------------------------------\n");
printf("Please press [Esc] return");
}
else
{
printf("-------------------------------------------------------------------------------\n");
printf("数学     0 ~ 59:%5d (人)\n",ma[0]);
printf("数学    60 ~ 69:%5d (人)\n",ma[1]);
printf("数学    70 ~ 79:%5d (人)\n",ma[2]);
printf("数学    80 ~ 89:%5d (人)\n",ma[3]);
printf("数学   90 ~ 100:%5d (人)\n",ma[4]);
printf("-------------------------------------------------------------------------------\n");
printf("英语      0 ~ 59:%5d (人)\n",en[0]);
printf("英语     60 ~ 69:%5d (人)\n",en[1]);
printf("英语     70 ~ 79:%5d (人)\n",en[2]);
printf("英语     80 ~ 89:%5d (人)\n",en[3]);
printf("英语    90 ~ 100:%5d (人)\n",en[4]);
printf("-------------------------------------------------------------------------------\n");
printf("C 语言    0 ~ 59:%5d (人)\n",cl[0]);
printf("C 语言   60 ~ 69:%5d (人)\n",cl[1]);
printf("C 语言   70 ~ 79:%5d (人)\n",cl[2]);
printf("C 语言   80 ~ 89:%5d (人)\n",cl[3]);
printf("C 语言  90 ~ 100:%5d (人)\n",cl[4]);
printf("-------------------------------------------------------------------------------\n");
printf("数学  成绩最高分的学生 : 学号:%-8d成绩 :%-5d\n",pma->no,pma->score[0]);
printf("英语  成绩最高分的学生 : 学号:%-8d成绩 :%-5d\n",pen->no,pen->score[1]);
printf("C语言 成绩最高分的学生 : 学号:%-8d成绩 :%-5d\n",pcl->no,pcl->score[2]);
printf("总分  成绩最高分的学生 : 学号:%-8d成绩 :%-5d\n",pmax->no,pmax->sum);
printf("-------------------------------------------------------------------------------\n");
printf("学生总人数 :%-4d(人)\n全部学生的平均分 :%4.2f\n",total,average);
printf("-------------------------------------------------------------------------------\n");
printf("请按[Esc]键退出"); 
}
do{
ch = getch();
}while(ch != 27);
}


void swapint(int *p1,int *p2)
{
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}


void swapchar(char p1[],char p2[])
{
char temp[20];
strcpy(temp,p1);
strcpy(p1,p2);
strcpy(p2,temp);
}
 
int select_sort(int choice)
{
SS *p,*p1,*p2;
char ch;
char temp[20];
p1 = head;
while(p1 != NULL)
{
p2 = p1->next;
p = p1;
while(p2 != NULL)
{
switch(choice)
{
case 1:if(p->sum < p2->sum) p = p2;break;
case 2:if(p->sum > p2->sum) p = p2;break;
case 3:if(p->score[0] < p2->score[0]) p = p2;break;
case 4:if(p->score[0] > p2->score[0]) p = p2;break;
case 5:if(p->score[1] < p2->score[1]) p = p2;break;
case 6:if(p->score[1] > p2->score[1]) p = p2;break;
case 7:if(p->score[2] < p2->score[2]) p = p2;break;
case 8:if(p->score[2] > p2->score[2]) p = p2;break;
case 9:if(p->no > p2->no) p = p2;break;
default:
if(z==1)
printf("\t\t\tInput error,fail to sort !\n");
else
printf("\t\t\t输入有误,排序失败!\n");
printf("\t\t\t请按[Esc]键返回主菜单...\n");
do{
ch = getch();
}while(ch != 27);
return 0;
}
p2 = p2->next;
}
swapchar(p->name,p1->name);
swapchar(p->sex,p1->sex);
swapint(&p->no,&p1->no);
swapint(&p->age,&p1->age);
swapint(&p->score[0],&p1->score[0]);
swapint(&p->score[1],&p1->score[1]);
swapint(&p->score[2],&p1->score[2]);
swapint(&p->sum,&p1->sum);
p1 = p1->next;
}
return 1;
}


void order()
{
char ch;
int choice;
system("cls");
z==1?printf("-------------------------------Sort Student Score-------------------------------\n"):
printf("----------------------------------排序学生成绩----------------------------------\n");
if(head==NULL)
{
z==1?printf("\n\t\tno record!\nPlease press any key to Mainmenu...\n"):
printf("\t\t没有记录!\n请按任意键返回主菜单...\n");
getch();
return; 
}
if(z==1)
{
printf("\n\t\t\t\tPlease choose way of sorting\n\n");
printf("\t\t\t+----------------------------------+\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t|    [1] High to low by sum        |\n");
printf("\t\t\t|    [2] Low to high by sum        |\n");
printf("\t\t\t|    [3] High to low by Math       |\n");
printf("\t\t\t|    [4] Low to high by Math       |\n");
printf("\t\t\t|    [5] High to low by English    |\n");
printf("\t\t\t|    [6] Low to high by English    |\n");
printf("\t\t\t|    [7] High to low by C language |\n");
printf("\t\t\t|    [8] Low to high by C language |\n");
printf("\t\t\t|    [9] By No                     |\n");
printf("\t\t\t|    [0] Quit                      |\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t+----------------------------------+\n");
printf("\n\t 请输入你的选择(0-9):");
}
else
{
printf("\n\t\t\t\t请选择你要的排序方式\n\n");
printf("\t\t\t+----------------------------------+\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t|       [1] 总分由高到低           |\n");
printf("\t\t\t|       [2] 总分由低到高           |\n");
printf("\t\t\t|       [3] 数学成绩由高到低       |\n");
printf("\t\t\t|       [4] 数学成绩由低到高       |\n");
printf("\t\t\t|       [5] 英语成绩由高到低       |\n");
printf("\t\t\t|       [6] 英语成绩由低到高       |\n");
printf("\t\t\t|       [7] C语言成绩由高到低      |\n");
printf("\t\t\t|       [8] C语言成绩由低到高      |\n");
printf("\t\t\t|       [9] 学生学号               |\n");
printf("\t\t\t|       [0] 退出                   |\n");
printf("\t\t\t|                                  |\n");
printf("\t\t\t+----------------------------------+\n");
printf("\n\t 请输入你的选择(0-9):");
}
scanf("%d",&choice);
if(select_sort(choice))
print();
}


void save()
{
FILE *fp;
SS *p;
if(head==NULL)
{
z==1?printf("\n\t\t\tno record,can not save!\n\t\t\tPlease press any key to Mainmenu...\n"):
printf("\n\t\t\t没有记录,无需保存!\n\t\t\t请按任意键返回主菜单...\n");
getch();
return; 
}
fp = fopen("database.txt","w");
if(!fp)
{
if(z==1)
printf("\nCan not open the file!\nPlease press any key return to mainmenu...");
else
printf("\n打开文件失败!\n请按任意键返回主菜单...");
getch();
return;
}
fprintf(fp,"%d\n%d\n%d\n",z,c,total);
for(p = head; p != NULL; p = p->next)
{
fprintf(fp,"%d\t%s\t\t%s\t%d\t%d\t%d\t%d\t%d\n",p->no,p->name,p->sex,p->age,p->score[0],p->score[1],p->score[2],p->sum);
}
fclose(fp);
z==1?printf("\n\t\tSave successfully,press any key to continue\n"):
printf("\n\t\t\t数据保存成功,请按任意键继续\n");
getch();
}


void free_all()
{
SS *p1, *p2;
p1 = p2=head; 
while(p1)
{
p2=p1->next;
free (p1);
p1 = p2;
}
}


void language()
{
int choice;
system("cls");
z==1?printf("---------------------------------Change Language--------------------------------\n\n\n"):
printf("------------------------------------更改语言------------------------------------\n\n\n");
printf("\t\t     +----------------------------------+\n");
printf("\t\t     |                                  |\n");        
printf("\t\t     |           [1] English            |\n");
  printf("\t\t     |           [2] 简体中文           |\n");
printf("\t\t     |                                  |\n");   
    printf("\t\t     +----------------------------------+\n");
    z==1?printf("\n\t\t     Please input your choice:"):
    printf("\n\t\t     请输入您的选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:z = 1;break;
case 2:z = 2;break;
default:error();getch();
}
}


void theme1()
{
int choice;
while(1)
{
system("cls");
printf("----------------------------------Change Theme----------------------------------\n\n\n");
printf("\t\t+------------------------------------------+\n");
printf("\t\t|                                          |\n");        
printf("\t\t|    [1] Classical black [7] Red           |\n");
printf("\t\t|    [2] Mystery black   [8] Yellow        |\n");
printf("\t\t|    [3] Black           [9] Pink          |\n");
printf("\t\t|    [4] White           [10] blue         |\n");
printf("\t\t|    [5] Green           [11] Bule screen  |\n");
printf("\t\t|    [6] Wathet          [12] Flame red    |\n");
printf("\t\t|                                          |\n");   
    printf("\t\t+------------------------------------------+\n");
    printf("\n\t\t   choose [0] to quit\n");
printf("\n\t\t   Please input your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:c = 1;color();break;
case 2:c = 2;color();break;
case 3:c = 3;color();break;
case 4:c = 4;color();break;
case 5:c = 5;color();break;
case 6:c = 6;color();break;
case 7:c = 7;color();break;
case 8:c = 8;color();break;
case 9:c = 9;color();break;
case 10:c = 10;color();break;
case 11:c = 11;color();break;
case 12:c = 12;color();break;
case 0:return;
}
}
return;
}


void theme()
{
int choice;
if(z==1)
{
theme1();
return;
}
while(1)
{
system("cls");
printf("------------------------------------更改主题------------------------------------\n\n\n");
printf("\t\t  +----------------------------------------+\n");
printf("\t\t  |                                        |\n");        
printf("\t\t  |      [1] 经典黑       [7] 纯红         |\n");
printf("\t\t  |      [2] 神秘黑       [8] 纯黄         |\n");
printf("\t\t  |      [3] 纯黑         [9] 粉红         |\n");
printf("\t\t  |      [4] 纯白         [10] 经典蓝      |\n");
printf("\t\t  |      [5] 纯绿         [11] 蓝屏蓝      |\n");
printf("\t\t  |      [6] 纯青         [12] 火焰红      |\n");
printf("\t\t  |                                        |\n");   
    printf("\t\t  +----------------------------------------+\n");
    printf("\n\t\t     选择[0]退出\n");
printf("\n\t\t     请输入您的选择:");
scanf("%d",&choice);
switch(choice)
{
case 0:return;
case 1:c = 1;color();break;
case 2:c = 2;color();break;
case 3:c = 3;color();break;
case 4:c = 4;color();break;
case 5:c = 5;color();break;
case 6:c = 6;color();break;
case 7:c = 7;color();break;
case 8:c = 8;color();break;
case 9:c = 9;color();break;
case 10:c = 10;color();break;
case 11:c = 11;color();break;
case 12:c = 12;color();break;
default:error();getch();
}
}
return;
}


void findhelp1()
{
char ch;
system("cls");
printf("--------------------------------------Help--------------------------------------\n\n");
printf("\n    1、Please save data before quit software in order to avoid lose data!\n");
printf("\n    2、When input the student's name,don't input[Space]or[Tab],\n");
printf("\n       it will lead to error!");
printf("\n\n\n\n\t\t\tPlease press [Esc] to return");
do{
ch = getch();
}while(ch != 27);
}


void findhelp()
{
char ch;
if(z==1)
{
findhelp1();
return;
}
system("cls");
printf("--------------------------------------帮助--------------------------------------\n\n");
printf("\n1、请在正常退出系统前记得保证保存好已输入的学生信息,以免数据丢失!\n");
printf("\n2、在输入学生姓名时,名字中不能带有空格,否则会造成信息错乱!\n");
printf("\n\n\n\n\t\t\t请按 [Esc] 键返回");
do{
ch = getch();
}while(ch != 27);
}


void about1()
{
char ch;
system("cls");
printf("--------------------------------About This Software-----------------------------\n");
printf("\n\n\n\n\t\t+--------------------------------------------+\n");
printf("\t\t|                                            |\n");        
    printf("\t\t|    Softname: New Students score            |\n");
    printf("\t\t|    Administrate System V1.0                |\n");
    printf("\t\t|    Developer:lingfengLTS                   |\n");
printf("\t\t|    The new of this software:               |\n");
printf("\t\t|    [1] User can change Chinese & English   |\n");
printf("\t\t|    [2] User can change the theme           |\n");
printf("\t\t|                                            |\n");
    printf("\t\t+--------------------------------------------+\n");
    printf("\n\t\t\tPlease press [Esc] to return");
    do{
ch = getch();
}while(ch != 27);
}


void about()
{
char ch;
if(z==1)
{
about1();
return;
}
system("cls");
printf("------------------------------------关于本软件----------------------------------\n");
printf("\n\n\n\n\t\t+--------------------------------------------+\n");
printf("\t\t|                                            |\n");        
    printf("\t\t|    软件名:新一代学生成绩管理系统 V1.0      |\n");
    printf("\t\t|    开发者:凌锋LTS                          |\n");
printf("\t\t|    本软件的亮点有:                         |\n");
printf("\t\t|    [1] 用户能切换中文和英文两种语言        |\n");
printf("\t\t|    [2] 可以自由改变主题                    |\n");
printf("\t\t|                                            |\n");
    printf("\t\t+--------------------------------------------+\n");
    printf("\n\t\t\t请按 [Esc] 键返回");
    do{
ch = getch();
}while(ch != 27);
}


void help_menu1()
{
system("cls");
printf("------------------------------------Settings------------------------------------\n\n\n");
    printf("\t\t     +----------------------------------+\n");
printf("\t\t     |                                  |\n");        
    printf("\t\t     |          [1] Change language     |\n");
    printf("\t\t     |          [2] Change Theme        |\n");
printf("\t\t     |          [3] Help                |\n");
printf("\t\t     |          [4] About               |\n");
printf("\t\t     |          [0] Return              |\n");
printf("\t\t     |                                  |\n");
    printf("\t\t     +----------------------------------+\n");
    printf("\n\t\t     Please input your choice:");
}


void help_menu2()
{
system("cls");
printf("--------------------------------------设置--------------------------------------\n\n\n");
    printf("\t\t     +----------------------------------+\n");
printf("\t\t     |                                  |\n");        
    printf("\t\t     |          [1] 更改语言            |\n");
    printf("\t\t     |          [2] 更改主题            |\n");
printf("\t\t     |          [3] 查看帮助            |\n");
printf("\t\t     |          [4] 关于本软件          |\n");
printf("\t\t     |          [0] 返回主菜单          |\n");
printf("\t\t     |                                  |\n");
    printf("\t\t     +----------------------------------+\n");
    printf("\n\t\t     请输入您的选择:");
}


void help()
{
char ch;
int choice;
while(1)
{
z==1?help_menu1():help_menu2();
        scanf("%d",&choice);
        switch(choice)
        {
case 0: return;
    case 1:language();break;
case 2:theme();break; 
    case 3:findhelp();break;
    case 4:about();break;
    default:
    z==1?
    printf("\n\t\t     Input error!please input again\n\t\t     or press [Esc] return to Mainmenu:"):
            printf("\n\t\t     输入有误!请重新输入\n\t\t     或按[Esc]键返回主菜单:");
            if((ch = getch())==27)
return;
        }
}
}