学生管理系统

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
#define mall(student) (struct student *)malloc(sizeof(struct student))
struct student
{
    char xuehao[111];
    char name[111];
    int fen;
    struct student *hou;
}*fuz,*tou;
void gotoxy(int x,int y)
{

    COORD loc;
    loc.X  =  y;
    loc.Y  =  x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), loc);
}//坐标定位函数
void caidan()
{
    gotoxy(2,32);
    puts("学生管理系统");
    puts("");
    puts("                                  1.插入");
    puts("                                  2.删除");
    puts("                                  3.显示");
    puts("                                  4.修改");
    puts("                                  5.结束");
}
void rulie(char *mi,char *hao,int fen)
{
    struct student *p;
    p=mall(student);
    strcpy(p->name,mi);
    strcpy(p->xuehao,hao);
    p->fen=fen;
    p->hou=NULL;
    fuz->hou=p;
    fuz=p;
}
void charu()
{
    char mi[111];
    char hao[111];
    int fen;
    int n,m=1;
    system("cls");
    puts("请输入插入的学生个数");
    scanf("%d",&n);
    while(n--)
    {
        printf("第%d个学生\n",m++);
        puts("输入姓名");
        scanf("%s",mi);
        puts("输入学号");
        scanf("%s",hao);
        puts("输入成绩");
        scanf("%d",&fen);
        rulie(mi,hao,fen);
    }
    system("cls");
    caidan();
}
void xianshi()
{
    struct student *jb;
    int nb=0;
    jb=tou;

    while(jb->hou!=NULL)
    {
        nb=1;
        printf("姓名   %s\n学号   %s\n成绩   %d\n",jb->hou->name,jb->hou->xuehao,jb->hou->fen);
        puts("");
        jb=jb->hou;
    }
    if(nb==0)
    {
        puts("查询无果");
        return;
    }
    puts("按任意键返回");
    while(1)
    {
        while(_kbhit())
        {
            getch();
            system("cls");
            caidan();
            return;
        }
    }
}
int chulie(char *hao)
{
    struct student *jb;
    int w=0;
    struct student *lz;
    jb=tou;

    while(jb->hou!=NULL)
    {
        lz=jb;
        jb=jb->hou;
        if(strcmp(jb->xuehao,hao)==0)
        {
            w=1;
            break;
        }
    }
    if(w==0)
    {
        puts("查询无果,请保证数据的准确");
        return 1;
    }
    lz->hou=jb->hou;
    //delete jb;
    free(jb);
    puts("删除成功");
    return 0;
}
void del()
{
    int n,i=1;
    char abc[111];
    puts("请输入删除学生的个数");
    scanf("%d",&n);
    while(n--)
    {
        printf("第%d个\n",i++);
loop:
        puts("请输入学号");

        scanf("%s",abc);
        if(chulie(abc)==1)
        {
            goto loop;
        }
        Sleep(1000);
    }
    system("cls");
    caidan();
}
int xiugai(char *hao)
{
    int w=0;
    struct student *jb;
    jb=tou;

    while(jb->hou!=NULL)
    {
        jb=jb->hou;
        if(strcmp(jb->xuehao,hao)==0)
        {
            w=1;
            break;
        }
    }
    if(w==0)
    {
        puts("查询无果,请保证数据的准确");
        return 1;
    }
    else
    {
        char ao[123];
        int k;
        puts("找到目标,请输入需要修改的选项:1,姓名  2,学号  3,成绩,0 返回");

        scanf("%d",&k);

        if(k==1)
        {
            puts("请输入姓名");
            scanf("%s",ao);
            strcpy(jb->name,ao);
        }
        else if(k==2)
        {
            puts("请输入学号");
            scanf("%s",ao);
            strcpy(jb->xuehao,ao);
        }
        else if(k==3)
        {
            puts("请输入成绩");
            scanf("%d",&k);
            jb->fen=k;
        }
        else if(k==0)
        {
            return 2;
        }
        puts("修改成功");
        Sleep(1000);
    }
    return 0;
}
void gai()
{
    int n,i=1,yy;
    char abc[111];
    puts("请输入修改学生的个数");
    scanf("%d",&n);
    while(n--)
    {
        printf("第%d个\n",i++);
loop:
        puts("请输入学号");
        scanf("%s",abc);
        yy=xiugai(abc);
        if(yy==1)
        {
            goto loop;
        }
        else if(yy==2)
        {
            system("cls");
            caidan();
            return;
        }
    }
    system("cls");
    caidan();
}
void paixu()
{
    struct student *jb,*lz,*st;
    int n=0;
    for(jb=tou->hou; jb->hou!=NULL; jb=jb->hou)
        n++;
    while(n--)
    {
        for(lz=tou->hou,st=tou; lz->hou!=NULL; lz=lz->hou)
        {
            if((lz->fen)<(lz->hou->fen))
            {
                struct student *mao;
                mao=lz;
                st->hou=mao->hou;
                mao->hou=st->hou->hou;
                st->hou->hou=mao;
                lz=st->hou;
            }
            st=st->hou;
        }
    }
}
int main()
{
    FILE *gs;
    char mi[111],hao[111];
    int w;
    int fen;
    struct student *jb;
    if((gs=fopen("123.txt","r"))==NULL)
        gs=fopen("123.txt","w+");
    system("color 1f");
    fuz=mall(student);
    tou=fuz;
    tou->hou=NULL;
    caidan();
    while(fscanf(gs,"%s%s%d",mi,hao,&fen)!=EOF)
        rulie(mi,hao,fen);
    fclose(gs);
    while(1)
    {
        scanf("%d",&w);
        if(w==1)
        {
            charu();
        }
        else if(w==3)
        {
            paixu();
            xianshi();
        }
        else if(w==5)
        {
            FILE *gs;
            if((gs=fopen("123.txt","w+"))==NULL)
            {
                puts("打开错误");
                getch();
                exit(1);
            }
            jb=tou;
            while(jb->hou!=NULL)
            {
                fprintf(gs,"%s\n%s\n%d\n",jb->hou->name,jb->hou->xuehao,jb->hou->fen);
                jb=jb->hou;
            }
            fclose(gs);
            return 0;
        }
        else if(w==2)
        {
            del();
        }
        else if(w==4)
        {
            gai();
        }
        else
        {
            puts("输入错误");
            Sleep(1000);
            system("cls");
            caidan();
        }
    }
    return 0;
}//VC可运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值