学生系统统计—|—《》—|—

//统计没有完成,要求输出最高分、最低分、总分平均数、和最高低分学生信息。大佬救命;
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
#include

typedef struct Node
{
int ID;// 学号
char Name[50];// 姓名
char Sex[10];// 性别
char Class[50];// 班级
char Room[20];// 宿舍号
int math;//数学
int chinese;//语文
int English;//英语
int Score;// 总成绩
struct Node* next;// 指针域
}node;

node list;// 链表

// 读取文件
int Read_FILE(node* L);

// 保存文件
int Save_FILE(node* L);

int main();

// 主菜单界面
void welcome();

// 增加学生信息
void Add(node* L, node e);// 功能
void Add_Printf();// 界面

// 删除学生信息
void Delete_Printf(node* L);// 界面
void Delete(node* s);// 功能

// 修改学生信息
void Fix(node* L);

// 查询学生信息
void Search_Printf(node* L);// 界面
node* Search_id(int id, node* L);// 按学号进行查找
node* Search_name(char name[], node* L);// 按姓名进行查找

// 输出学生信息
void Print(node* L);// 功能
void Print_Printf();// 界面

// 排序学生信息
void Sort(node* L);
bool cmp_big_ID(node e1, node e2);// 学号从大到小
bool cmp_big_Score(node e1, node e2);// 成绩从大到小
bool cmp_small_ID(node e1, node e2);// 学号从小到大
bool cmp_small_Score(node e1, node e2);// 成绩从小到大
//统计学生信息
void Print1(node* L);// 功能

// 退出管理系统
void goodbye();

int main()
{
int choice = 0;
Read_FILE(&list);
while (true)
{
welcome();
scanf("%d", &choice);
switch (choice)
{
case 1:// 增加学生信息
Add_Printf();
break;
case 2:// 删除学生信息
Delete_Printf(&list);
break;
case 3:// 修改学生信息
Fix(&list);
break;
case 4:// 查询学生信息
Search_Printf(&list);
break;
case 5:// 输出学生信息
Print(&list);
break;
case 6:// 排序学生信息
Sort(&list);
break;
case 7://统计
Print1(&list);
break;
case 8:
system("cls");
printf("**************************************\n");
printf("
版权所有 翻版罚款100元 \n");
printf("
制作人: MS 政 *\n");
printf("***************************************\n");
system("pause");
system("cls");
break;
case 0:// 退出管理系统
goodbye();
break;
}
printf("是否需要继续操作?(Yes:1 / No:0):");
scanf("%d", &choice);
if (choice == 0)
{
break;
}
}
return 0;
}

void welcome()
{
{
system("cls");
printf("==============================学生成绩管理系统菜单====================================\n");
printf("0、退出 ");
printf("1、输入 ");
printf("2、删除 ");
printf("3、修改 ");
printf("4、查找 ");
printf("5、显示 ");
printf("6、排序 ");
printf("7、统计 ");
printf("8、帮助\n");
printf("请输入你的选项:");
printf("请选择想要实现的功能(数字):");
}
}

// 读取文件
int Read_FILE(node* L)
{
FILE* pfRead = fopen("student_information.txt", "r");
node st;
node* s;
node* t = L;

if (pfRead == NULL)
{
    return 0;
}

while (fscanf(pfRead, "%d %s %s %s %s  %d %d %d %d", &st.ID, st.Name, st.Sex, st.Class, st.Room, &st.math, &st.chinese, &st.English, &st.Score) != EOF)
{
    s = (node*)malloc(sizeof(node));

    *s = st;

    // 尾插法
    t->next = s;
    t = s;
    t->next = NULL;
}

return 1;

}

// 保存文件
int Save_FILE(node* L)
{
FILE* pfWrite = fopen("student_information.txt", "w");
if (pfWrite == NULL)
{
return 0;
}

node* p = L->next;

while (p != NULL)
{
    fprintf(pfWrite, " %d %s %s %s %s %d\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
    p = p->next;
}

return 1;

}

// 增加学生信息
void Add_Printf()
{
system("cls");
node st;
printf("请输入新增学生的相关信息:\n");
printf("学号:");
scanf("%d", &st.ID);
printf("姓名:");
scanf("%s", st.Name);
printf("性别:");
scanf("%s", st.Sex);
printf("出生日期(xxxx.xx.xx):");
scanf("%s", st.Class);
printf("联系方式(请输入手机号码):");
scanf("%s", st.Room);
printf("数学:");
scanf("%d", &st.math);
printf("语文:");
scanf("%d", &st.chinese);
printf("英语:");
scanf("%d", &st.English);
st.Score =
st.math +
st.chinese +
st.English;
Add(&list, st);
}

void Add(node* L, node e)
{
// 头插法
node* p = L;
node* s = (node*)malloc(sizeof(node));
*s = e;

s->next = p->next;
p->next = s;

Save_FILE(L);

}

// 删除学生信息
void Delete_Printf(node* L)
{
system("cls");
int id;

node* p;

printf("请输入要删除的学生的学号:");
scanf("%d", &id);
node* st = Search_id(id, L);
p = st;

if (st == NULL)
{
    printf("查无此人!\n");
    return;
}

st = st->next;

printf("________________________________________________________________\n");
printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
printf("________________________________________________________________\n");
printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", st->ID, st->Name, st->Sex, st->Class, st->Room, st->math, st->chinese, st->English, st->Score);
printf("________________________________________________________________\n");

Delete(p);
// 保存信息
Save_FILE(L);

}

void Delete(node* s)
{
node* t = s->next;

s->next = t->next;
t->next = NULL;

free(t);

}

// 修改学生信息
void Fix(node* L)
{
system("cls");
int id;
printf("请输入要修改的学生的学号:");
scanf("%d", &id);
node* st = Search_id(id, L);

if (st == NULL)
{
    printf("查无此人!\n");
    return;
}

st = st->next;

int choice = 0;
while (1)
{
    system("cls");

    // 输出一次所要修改的学生成绩
    printf("________________________________________________________________\n");
    printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
    printf("________________________________________________________________\n");
    printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", st->ID, st->Name, st->Sex, st->Class, st->Room, st->math, st->chinese, st->English, st->Score);
    printf("________________________________________________________________\n");

    printf("修改姓名 ---- 1\n");
    printf("修改性别 ---- 2\n");
    printf("修改出生日期 ---- 3\n");
    printf("修改联系方式 ---- 4\n");
    printf("修改数学成绩 ---- 5\n");
    printf("修改数学成绩 ---- 5\n");
    printf("修改语文成绩 ---- 6\n");
    printf("修改英语成绩 ---- 7\n");
    printf("请输入要修改的信息:");
    scanf("%d", &choice);

    switch (choice)
    {
    case 1:
        printf("请输入姓名:");
        scanf("%s", st->Name);
        break;
    case 2:
        printf("请输入性别:");
        scanf("%s", st->Sex);
        break;
    case 3:
        printf("请输入出生日期:");
        scanf("%s", st->Class);
        break;
    case 4:
        printf("请输入联系方式:");
        scanf("%s", st->Room);
        break;
    case 5:
        printf("请输入数学成绩:");
        scanf("%d", st->math);
        break;
    case 6:
        printf("请输入语文成绩:");
        scanf("%d", st->chinese);
        break;
    case 7:
        printf("请输入英语成绩:");
        scanf("%d", st->English);
        break;

    }
    printf("是否继续修改该学生信息?(Yes:1 / No:0):");
    scanf("%d", &choice);
    if (choice == 0)
    {
        break;
    }
}

// 修改完成后该学生的信息
printf("________________________________________________________________\n");
printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
printf("________________________________________________________________\n");
printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", st->ID, st->Name, st->Sex, st->Class, st->Room, st->math, st->chinese, st->English, st->Score);
printf("________________________________________________________________\n");

// 保存信息
Save_FILE(L);

}

// 查询学生信息
void Search_Printf(node* L)
{
system("cls");
int choice = 0;
printf("按照学号查询 ---- 1\n");
printf("按照姓名查询 ---- 2\n");
printf("请输入查询方式:");
scanf("%d", &choice);

int id;
char name[50];
node* st;
if (choice == 1)
{
    printf("请输入要查询的学号:");
    scanf("%d", &id);
    st = Search_id(id, L);

    if (st == NULL)
    {
        printf("查无此人!\n");
    }
    else
    {
        st = st->next;
        printf("________________________________________________________________\n");
        printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
        printf("________________________________________________________________\n");
        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", st->ID, st->Name, st->Sex, st->Class, st->Room, st->math, st->chinese, st->English, st->Score);
        printf("________________________________________________________________\n");
    }
}
else if (choice == 2)
{
    printf("请输入要查询的姓名:");
    scanf("%s", name);
    st = Search_name(name, L);

    if (st == NULL)
    {
        printf("查无此人!\n");
    }
    else
    {
        st = st->next;
        printf("________________________________________________________________\n");
        printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
        printf("________________________________________________________________\n");
        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", st->ID, st->Name, st->Sex, st->Class, st->Room, st->math, st->chinese, st->English, st->Score);
        printf("________________________________________________________________\n");
    }
}

}

// 按学号进行查找
node* Search_id(int id, node* L)
{
node* p = L;

while (p->next != NULL)
{
    if (p->next->ID == id)
    {
        return p;
    }
    p = p->next;
}
return NULL;

}

// 按姓名进行查找
node* Search_name(char name[], node* L)
{
node* p = L;

while (p->next != NULL)
{
    if (strcmp(name, p->next->Name) == 0)
    {
        return p;
    }
    p = p->next;
}
return NULL;

}

// 输出学生信息
void Print(node* L)
{
system("cls");
node* p = L->next;
Print_Printf();
if (p != NULL)
{
while (p != NULL)
{
printf("________________________________________________________________\n");
printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
printf("________________________________________________________________\n");
p = p->next;
}
}
}

void Print_Printf()
{
printf("________________________________________________________________\n");
printf("|学号\t|姓名\t|性别\t|出生日期\t|联系方式\t|数学\t|语文\t|英语\t|总成绩\t|\n");
printf("________________________________________________________________\n");
}
void Sort(node* L)
{
system("cls");
int choice = 0;
printf("按照学号从大到小排序 ---- 1\n");
printf("按照学号从小到大排序 ---- 2\n");
printf("按照成绩从大到小排序 ---- 3\n");
printf("按照成绩从小到大排序 ---- 4\n");
printf("请选择排序方式:");
scanf("%d", &choice);

int flag = 0;
for (node* p = L->next; p != NULL; p = p->next)
{
    for (node* q = p; q != NULL; q = q->next)
    {
        switch (choice)
        {
        case 1:
            if (!cmp_big_ID(*p, *q))
            {
                flag = 1;
                system("cls");
                node* p = L->next;
                Print_Printf();
                if (p != NULL)
                {
                    while (p != NULL)
                    {
                        printf("________________________________________________________________\n");
                        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
                        printf("________________________________________________________________\n");
                        p = p->next;
                    }
                }

            }
            break;
        case 2:
            if (!cmp_small_ID(*p, *q))
            {
                flag = 1;
                system("cls");
                node* p = L->next;
                Print_Printf();
                if (p != NULL)
                {
                    while (p != NULL)
                    {
                        printf("________________________________________________________________\n");
                        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
                        printf("________________________________________________________________\n");
                        p = p->next;
                    }
                }
            }
            break;
        case 3:
            if (!cmp_big_Score(*p, *q))
            {
                flag = 1;
                system("cls");
                node* p = L->next;
                Print_Printf();
                if (p != NULL)
                {
                    while (p != NULL)
                    {
                        printf("________________________________________________________________\n");
                        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
                        printf("________________________________________________________________\n");
                        p = p->next;
                    }
                }
            }
            break;
        case 4:
            if (!cmp_small_Score(*p, *q))
            {
                flag = 1;
                system("cls");
                node* p = L->next;
                Print_Printf();
                if (p != NULL)
                {
                    while (p != NULL)
                    {
                        printf("________________________________________________________________\n");
                        printf("%d\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n", p->ID, p->Name, p->Sex, p->Class, p->Room, p->math, p->chinese, p->English, p->Score);
                        printf("________________________________________________________________\n");
                        p = p->next;
                    }
                }
            }
            break;
        }
        if (flag == 1)
        {
            // 交换数据域
            node t = *p;
            *p = *q;
            *q = t;
            // 处理指针域
            t.next = p->next;
            p->next = q->next;
            q->next = t.next;
            flag = 0;
        }
    }
}

}

// 学号从大到小 !cmp_big_ID (*p, *q)
bool cmp_big_ID(node e1, node e2)
{
return e1.ID > e2.ID;
}
// 成绩从大到小
bool cmp_big_Score(node e1, node e2)
{
return e1.Score > e2.Score;
}

// 学号从小到大
bool cmp_small_ID(node e1, node e2)
{
return e1.ID < e2.ID;
}
// 成绩从小到大
bool cmp_small_Score(node e1, node e2)
{
return e1.Score < e2.Score;
}
//tj
void Print1(node* L)

{

system("cls");
int  c = 0, m = 0, z = 0, k = 0, y = 0, v = 0, j = 0, text;
node* p = L->next;
while (p != NULL)
{

    if (p->Score < 180)c++;
    if (p->Score > 180)m++;
    p = p->next;
}
printf("总分不及格数人:%d人", c);
printf("总分及人数格:%d人", m);
z = c + m;
printf("已录入人数%d\n", z);
text = p->Score;

}

void goodbye()

{
system("cls");
printf("欢迎下次使用学生信息管理系统!");
exit(0);// 结束程序
}