成绩管理

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#define isize 100
void menu();
void menu1();
typedef struct
{
    int math;
    int english;
    int physics;
} Class;
typedef struct
{
    long long int  snum;
    char sname[20];
    Class score;

} student;
typedef struct{
    student *elem;
    int length;
    int listsize;
}sqlist;
typedef struct stu_node
{

    student data ;
    struct stu_node *next;
} stu,*LinkList;
void charu(stu_node *head, stu_node *r)
{
    stu_node *p, *q;
    p = head -> next;;
    q = head;
    while(p)
    {
        if(p -> data.snum >= r -> data.snum)
        {
            break;
        }
        else
        {
            q = q -> next;
            p = p -> next;
        }
    }
    r -> next = q -> next;
    q -> next = r;
}
void luru(sqlist l, stu_node *head)
{
    system("cls");
    printf("请输入学生数量:");
    int n;
    scanf("%d", &n);
    system("cls");
    int i;
    for (i = 0 ; i < n; i++)		//依次录入信息
    {
        printf ("请输入学号(8位): ");
        scanf("%lld", &l.elem[i].snum);
        printf ("请输入姓名: ");
        scanf ("%s",l.elem[i].sname);
        printf ("请输入数学成绩: ");
        scanf ("%d",&l.elem[i].score.math);
        printf ("请输入英语成绩: ");
        scanf ("%d",&l.elem[i].score.english);
        printf ("请输入物理成绩: ");
        scanf ("%d",&l.elem[i].score.physics);
        system("cls");
    }
    l.length = n;
    for(i = 0; i < l.length; i++){
        stu_node *p;
        p = (stu_node *)malloc(sizeof(stu_node));
        p -> next = NULL;
        p ->data.snum = l.elem[i].snum;
        strcpy(p -> data.sname, l.elem[i].sname);
        p -> data.score.math = l.elem[i].score.math;
        p -> data.score.english = l.elem[i].score.english;
        p -> data.score.physics = l.elem[i].score.physics;
        charu(head, p);
    }
    system("cls");
}
void charu1(stu_node *head)
{
    system("cls");
    stu_node *p;
    p = (stu_node *)malloc(sizeof(stu_node));
    p -> next = NULL;
    printf ("请输入学号(8位): ");
    scanf("%lld", &p -> data.snum);
    printf ("请输入姓名: ");
    scanf ("%s",p -> data.sname);
    printf ("请输入数学成绩: ");
    scanf ("%d",&p -> data.score.math);
    printf ("请输入英语成绩: ");
    scanf ("%d",&p -> data.score.english);
    printf ("请输入物理成绩: ");
    scanf ("%d",&p -> data.score.physics);
    charu(head, p);
    system("cls");
}
void fin(stu_node *head)
{
    system("cls");
    printf("请输入学号:");
    long long int x;
    scanf("%lld", &x);
    stu_node *p = head -> next;
    int flag = 0;
    while(p)
    {
        if(p -> data.snum == x)
        {
            flag = 1;
            break;
        }
        p = p -> next;
    }
    if(flag)
    {
        system("cls");
        printf("学号:%lld\n", x);
        printf("姓名:%s\n", p -> data.sname);
        printf("英语:%d\n", p ->data.score.english);
        printf("数学:%d\n", p ->data.score.math);
        printf("物理:%d\n", p ->data.score.physics);
        printf("按回车继续\n");
        getchar();
        getchar();
    }
    else
    {
        printf("无该学生信息\n");
        printf("按回车继续\n");
        getchar();
        getchar();
    }
}
void sanchu(stu_node *head)
{
    system("cls");
    printf("1 按学号删除\n");
    printf("2 按姓名删除\n");
    printf("请输入编号:");
    int x;
    scanf("%d", &x);
    while(x < 1 || x > 2)
    {
        printf("输入信息错误,请重新输入\n");
        getchar();
        getchar();
        system("cls");
        printf("1 按学号删除\n");
        printf("2 按姓名删除\n");
        printf("请输入编号:");
        scanf("%d", &x);
    }
    switch(x)
    {
    case 1:
    {
        system("cls");
        printf("请输入学号:");
        long long int y;
        scanf("%lld", &y);
        stu_node *p;
        p = head -> next;
        stu_node *q;
        q = head;
        while(p)
        {
            if(p ->data.snum == y)
            {
                q -> next = p -> next;
                p = q -> next;
            }
            else
            {
                q = q -> next;
                p = p -> next;
            }
        }
        break;
    }
    case 2:
    {
        system("cls");
        printf("请输入姓名\n");
        char ch[100];
        scanf("%s", ch);
        stu_node *p;
        p = head -> next;
        stu_node *q;
        q = head;
        while(p)
        {
            if(strcmp(ch, p ->data.sname) == 0)
            {
                q -> next = p -> next;
                p = q -> next;
            }
            else
            {
                q = q -> next;
                p = p -> next;
            }
        }
        break;
    }
    }
}
void out(stu_node *head)//输出
{
    system("cls");
    stu_node *p;
    p = head -> next;
    printf("%-15s%-15s%-15s%-15s%-15s\n", "学号", "姓名", "数学", "物理", "英语");
    while(p)
    {
        printf("%-15lld%-15s%-15d%-15d%-15d\n", p ->data.snum, p ->data.sname, p ->data.score.math, p ->data.score.physics, p ->data.score.english);
        p = p -> next;
    }
    if(head -> next == NULL)printf("无学生信息\n");
    printf("按回车继续\n");
    getchar();
    getchar();
}
//有小到大插入到链表中
void c_1(stu_node *head, stu_node *r)
{
    stu_node *p, *q;
    p = head -> next;;
    q = head;
    while(p)
    {
        if(p -> data.score.math <= r -> data.score.math)
        {
            break;
        }
        else
        {
            q = q -> next;
            p = p -> next;
        }
    }
    r -> next = q -> next;
    q -> next = r;
}
void c_2(stu_node *head, stu_node *r)
{
    stu_node *p, *q;
    p = head -> next;;
    q = head;
    while(p)
    {
        if(p -> data.score.english <= r -> data.score.english)
        {
            break;
        }
        else
        {
            q = q -> next;
            p = p -> next;
        }
    }
    r -> next = q -> next;
    q -> next = r;
}
void c_3(stu_node *head, stu_node *r)
{
    stu_node *p, *q;
    p = head -> next;;
    q = head;
    while(p)
    {
        if(p -> data.score.physics <= r -> data.score.physics)
        {
            break;
        }
        else
        {
            q = q -> next;
            p = p -> next;
        }
    }
    r -> next = q -> next;
    q -> next = r;
}
void out1(stu_node *head, stu_node *h_math, stu_node *h_english, stu_node *h_physics){//各学科成绩由大到小排序
    menu1();
    int x;
    scanf("%d", &x);
    while(x < 1 || x > 3){
        printf("输入信息错误,请重新输入\n");
        menu1();
        scanf("%d", &x);
    }
    system("cls");
    switch(x){
        case 1:{
            stu_node *p1;
            p1 = head -> next;
            while(p1){
                    stu_node *p;
                    p = (stu_node *)malloc(sizeof(stu_node));
                    p -> data.snum = p1 -> data.snum;
                    strcpy(p->data.sname, p1 ->data.sname);
                    p->data.score.math = p1->data.score.math;
                c_1(h_math, p);
                p1 = p1 -> next;
            }
            p1 = h_math -> next;
            printf("%-15s%-15s%-15s\n", "学号", "姓名", "数学");
            while(p1){
                printf("%-15lld%-15s%-15d\n",p1 -> data.snum, p1 -> data.sname, p1 ->data.score.math);
                p1 = p1 -> next;
            }
            h_math -> next = NULL;
            break;
        }
        case 2:{
            stu_node *p1;
            p1 = head -> next;
            while(p1){
                    stu_node *p;
                    p = (stu_node *)malloc(sizeof(stu_node));
                    p -> data.snum = p1 -> data.snum;
                    strcpy(p->data.sname, p1 ->data.sname);
                    p->data.score.english = p1->data.score.english;
                c_2(h_english, p);
                p1 = p1 -> next;
            }
            p1 = h_english -> next;
            printf("%-15s%-15s%-15s\n", "学号", "姓名", "英语");
            while(p1){
                printf("%-15lld%-15s%-15d\n",p1 -> data.snum, p1 -> data.sname, p1 ->data.score.english);
                p1 = p1 -> next;
            }
            h_english -> next = NULL;
            break;
        }
        case 3:{
            stu_node *p1;
            p1 = head -> next;
            while(p1){
                    stu_node *p;
                    p = (stu_node *)malloc(sizeof(stu_node));
                    p -> data.snum = p1 -> data.snum;
                    strcpy(p->data.sname, p1 ->data.sname);
                    p->data.score.physics = p1->data.score.physics;
                c_3(h_physics, p);
                p1 = p1 -> next;
            }
            p1 = h_physics -> next;
            printf("%-15s%-15s%-15s\n", "学号", "姓名", "物理");
            while(p1){
                printf("%-15lld%-15s%-15d\n",p1 -> data.snum, p1 -> data.sname, p1 ->data.score.physics);
                p1 = p1 -> next;
            }
            h_physics -> next = NULL;
            break;
        }
    }
    getchar();
    getchar();

}
int main()
{
    int flag = 1;
    int x;
    stu_node *head;
    stu_node *h_math;
    stu_node *h_english;
    stu_node *h_physics;
    sqlist l;
    l.elem = (student *)malloc(isize * sizeof(student));
    l.length = 0;
    l.listsize = isize;
    if(!l.elem){
        printf("分配内存失败\n");
        printf("按回车继续\n");
        getchar();
        getchar();
        exit(0);
    }

    head = (stu_node *)malloc(sizeof(stu_node));
    h_math = (stu_node *)malloc(sizeof(stu_node));
    h_english = (stu_node *)malloc(sizeof(stu_node));
    h_physics = (stu_node *)malloc(sizeof(stu_node));
    head -> next = NULL;
    h_math -> next = NULL;
    h_english -> next = NULL;
    h_physics -> next = NULL;
    while(flag)
    {
        menu();
        scanf("%d", &x);
        while(x < 1 || x > 7)
        {
            printf("输入信息错误,请重新输入\n");
            getchar();
            getchar();
            menu();
            scanf("%d", &x);
        }
        switch(x)
        {
        case 1:
            luru(l, head);
            break;
        case 2:
            charu1(head);
            break;
        case 3:
            fin(head);
            break;
        case 4:
            sanchu(head);
            break;
        case 5:
            out(head);
            break;
        case 6:
            out1(head, h_math, h_english, h_physics);
            break;
        case 7:
            flag = 0;
            break;
        }
    }
}
void menu()
{
    system("cls");
    printf("1 登录成绩\n");
    printf("2 插入成绩\n");
    printf("3 查询成绩\n");
    printf("4 删除成绩\n");
    printf("5 学生信息\n");
    printf("6 学科信息\n");
    printf("7 退出\n");
    printf("请输入编号:");
}
void menu1(){
    system("cls");
    printf("1 数学\n");
    printf("2 英语\n");
    printf("3 物理\n");
    printf("请输入编号:");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值