学生成绩管理系统

数据结构链表实现学生成绩管理系统

//consts.h

#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<stdio.h>
#include<limits.h>
#include<io.h>
#include<math.h>
#include<process.h>

#define TRUR 1
#define FALSE 0
#define OK 1
#define ERROR -1
#define INFEASIBLE -1

//st.cpp

#ifndef   MY_H_FILE      
#define   MY_H_FILE     
#include"consts.h"
#endif  

typedef struct node
{
    char num[110];
    int shuxue;
    int yingyu;
    int yuwen;
    int wuli;
    int huaxue;
    struct node *next;
}LinkList;

void CreateLinkList(LinkList *head,int *n)
{
    char num[110];
    int score,score1,score2,score3,score4;
    int i=1;
    LinkList *p=head;
    LinkList *s;
    printf("请输入学号,输入0结束输入:\n");
    scanf("%s",&num);
    while(1)
    {
        if(strcmp(num,"0")==0)
            break;
        s=(LinkList*)malloc(sizeof(LinkList));
        strcpy(s->num,num);
        printf("请输入数学成绩:\n");
        scanf("%d",&score);
        s->shuxue=score;
        printf("请输入英语成绩:\n");
        scanf("%d",&score1);
        s->yingyu=score1;
        printf("请输入语文成绩:\n");
        scanf("%d",&score2);
        s->yuwen=score2;
        printf("请输入物理成绩:\n");
        scanf("%d",&score3);
        s->wuli=score3;
        printf("请输入化学成绩:\n");
        scanf("%d",&score4);
        s->huaxue=score4;
        p->next=s;
        p=s;
        s->next=NULL;
        *n=*n+1;
        printf("请输入学生的学号,输入0结束输入:\n");
        scanf("%s",&num);
    }
}

void InsertStu(LinkList *head,char num[],int *n)
{
    LinkList *p;
    LinkList *s;
    int score,score1,score2,score3,score4;
    int flag=0;
    printf("请输入数学成绩:\n");
    scanf("%d",&score);
    printf("请输入英语成绩:\n");
    scanf("%d",&score1);
    printf("请输入语文成绩:\n");
    scanf("%d",&score2);
    printf("请输入物理成绩:\n");
    scanf("%d",&score3);
    printf("请输入化学成绩:\n");
    scanf("%d",&score4);
    p=head;
    while(p->next!=NULL)
    {
        if(strcmp(p->next->num,num)==0)
        {
            flag=1;break;
        }
        p=p->next;
    }
    if(flag==1)
    {
        p->next->shuxue=score;  
        p->next->yingyu=score1;
        p->next->yuwen=score2;
        p->next->wuli=score3;
        p->next->huaxue=score4;
        }
    else
    {
        s=(LinkList*)malloc(sizeof(LinkList));
        strcpy(s->num,num);
        s->shuxue=score;
        s->yingyu=score1;
        s->yuwen=score2;
        s->wuli=score3;
        s->huaxue=score4;
        p->next=s;
        p=s;
        s->next=NULL;   
        *n=*n+1;
    }
}

int DeleteStu(LinkList *head,char num[],int *n)
{
    LinkList *p=head;
    LinkList *s;
    if(p->next==NULL)
    {
        printf("表中没有任何记录。\n");
        return ERROR;
    }
    else
    {
        while(p!=NULL)
        {
            s=p->next;
            if(s!=NULL)
            {
                if(strcmp(s->num,num)==0)
                {
                    p->next=s->next;
                    *n=*n-1;
                    break;
                }
            }
            p=p->next;
        }
        printf("表中已经没有该学生记录。\n");
        return ERROR;
    }
}

void DisplayStu(LinkList *head)
{
    LinkList *h=head->next;
    printf("学号  数学  英语  语文  物理  化学\n");
    while(h!=NULL)
    {
        printf("%s\t%d\t%d\t%d\t%d\t%d\n",h->num,h->shuxue,h->yingyu,h->yuwen,h->wuli,h->huaxue);
        h=h->next;
    }
}


int main()
{
    LinkList *head;
    char num[110];
    int flag=0;
    int n=0;
    head=(LinkList*)malloc(sizeof(LinkList));
    head->next=NULL;
    CreateLinkList(head,&n);
    printf("学生总数为%d\n",n);
    if(head->next!=NULL)
        DisplayStu(head);
    printf("\n");
    printf("请输入要插入的学生的学号,以0结束:\n");
    scanf("%s",&num);
    while(1)
    {
        if(strcmp(num,"0")==0) break;
        InsertStu(head,num,&n);
        printf("学生总数为%d\n",n);
        DisplayStu(head);
        scanf("%s",&num);
    }

    printf("请输入要删除的学生的学号,以0结束:\n");
    scanf("%s",&num);
    while(1)
    {
        if(strcmp(num,"0")==0) break;
        flag=DeleteStu(head,num,&n);
        printf("学生总数为%d\n",n);
        DisplayStu(head);
        scanf("%s",&num);
    }
    return 0;
}
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值