| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2441 人关注过本帖, 1 人收藏
标题:编一个学生信息管理系统,求大神帮忙
只看楼主 加入收藏
lf1010849299
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2016-11-15
结帖率:75%
收藏(1)
已结贴  问题点数:20 回复次数:5 
编一个学生信息管理系统,求大神帮忙
题目要求:    1、从文件中读入学生相关信息存入链表(创建);
            2、实现对链表的插入/多关键字删除操作;
            3、实现对链表的多关键字排序操作;
            4、实现对链表的保存(原文件)和另存(新文件)功能;
            5、将功能实现为菜单形式,方便用户进行任意操作序列。
搜索更多相关主题的帖子: 管理系统 关键字 信息 用户 
2017-02-13 10:34
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:10 
参考~
https://bbs.bccn.net/thread-473336-1-1.html
九九曾经自己写的~上千行代码~要做好心理准备~~~~

PS:多关键字链表排序可以参考一下~

https://bbs.bccn.net/thread-474128-1-1.html

~~~~

[此贴子已经被作者于2017-2-13 10:40编辑过]


[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-02-13 10:37
yanzy
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:104
专家分:372
注 册:2017-2-7
收藏
得分:10 
明天写一下
代码来了,很粗糙,特别是排序算法,这两天卡这里了,以后再优化一下
程序代码:
/*
1、从文件中读入学生相关信息存入链表(创建);
2、实现对链表的插入/多关键字删除操作;
3、实现对链表的多关键字排序操作;
4、实现对链表的保存(原文件)和另存(新文件)功能;
5、将功能实现为菜单形式,方便用户进行任意操作序列。
*/
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdbool.h>

struct students {
    char name[20];//学生名字
    int number;//学生学号
    int classes;//班级
    float math;//数学成绩
    float chinese;//语文成绩
    float english;//英语成绩
    struct students *next;
};

struct students *student = NULL;//指向初始位置
bool yesorno = false;

struct students *insert(void);
struct students *find(char *str);
void dele(void);
void sort(void);
void search(void);
void save(void);
void save_as(void);
void read(void);
void quit(void);
void print(void);

int main(void)
{
    char code;

    for (;;)
    {
        printf("请选择您需要的操作\n");
        printf("输入(I),删除(D),排序(X),搜索(S),保存(B),另存(L),读取(R),退出(Q):\n");

        scanf(" %c", &code);
        while (getchar() != '\n')
            ;
        switch (code)
        {
        case 'i':case 'I':insert(); break;
        case 'd':case 'D':dele(); break;
        case 'x':case 'X':sort(); break;
        case 's':case 'S':search(); break;
        case 'b':case 'B':save(); break;
        case 'L':case 'l':save_as(); break;
        case 'r':case 'R':read(); break;
        case 'q':case 'Q':quit(); break;
        case 'p':case 'P':print(); break;
        default:printf("enter wrong.\n"); break;
        }
    }
}

struct students *find(char *str)
{
    struct students *tmp;
    for (tmp = student; tmp; tmp = tmp->next)
        if ((strcmp(str, tmp->name) == 0) || (strcmp(str, tmp->number) == 0))
            return tmp;
    if (tmp == NULL)
    {
        printf("Not found.\n");
        return NULL;
    }
}

struct students *insert(void)
{
    struct students *tmp = malloc(sizeof(struct students));
    if (tmp == NULL)
    {
        fprintf(stderr, "No momory space.\n");
        return;
    }
    printf("请输入学生所在班级:");
    scanf("%d", &tmp->classes);
    while (getchar() != '\n')
        ;
    printf("请输入学生名字:");
    gets(tmp->name);
    printf("请输入学生学号:");
    scanf("%d", &tmp->number);
    printf("请输入学生数学成绩:");
    scanf("%f", &tmp->math);
    printf("请输入学生语文成绩:");
    scanf("%f", &tmp->chinese);
    printf("请输入学生英语成绩:");
    scanf("%f", &tmp->english);

    tmp->next = student;
    student = tmp;
    yesorno = false;
    return student;
}

void dele(void)
{
    char code[20], ch;
    struct students *tmp, *tmp1;
    printf("请输入您要删除的学生名字或学号:");
    gets(code);
    tmp = find(code);
    if (tmp == NULL)
        return;
    printf("班级:%d\n", tmp->classes);
    printf("名字: ");
    puts(tmp->name);
    printf("学号: %d\n", tmp->number);
    printf("are you sure delete ?(y/n) : ");
    ch = getchar();
    if (ch == 'y' || ch == 'Y')
    {
        if (tmp == student)
            student = student->next;
        else
        {
            for (tmp1 = student; tmp1->next != tmp; tmp1 = tmp1->next)
                ;
            tmp1->next = tmp->next;
        }
        free(tmp);
        printf("delete success.\n");
    }
    yesorno = false;
    return;
}

void print(void)
{
    struct students *tmp;
    printf("Students data:\n");
    printf("classes     name        number      math        chinese     english     \n");
    for (tmp = student; tmp; tmp = tmp->next)
        printf("%-12d%-12s%-12d%-12g%-12g%-12g\n", tmp->classes, tmp->name, tmp->number, tmp->math, tmp->chinese, tmp->english);
    printf("\n\n");
    return;
}

void quit(void)
{
    if (yesorno)
        exit(0);
    else
    {
        printf("尚未保存,是否直接退出?返回(y),退出(n):");
        char code;
        for (;;)
        {
            scanf(" %c", &code);
            if (code == 'y' || code == 'Y')
                return;
            else if (code == 'n' || code == 'N')
                exit(0);
            else
                printf("Enter wrong,try again: ");
        }
    }
}

void save(void)
{
    FILE *fp;

    if ((fp = fopen("studentsdata.txt", "w")) == NULL)
    {
        fprintf(stderr, "Can't build studentsdata.txt\n");
        exit(0);
    }
    struct students *tmp;
    for (tmp = student; tmp; tmp = tmp->next)
    {
        fprintf(fp,"%d\n%s\n%d\n%.1f\n%.1f\n%.1f\n", tmp->classes, tmp->name, tmp->number, tmp->math, tmp->chinese, tmp->english);
    }
    fclose(fp);
    printf("存储完毕\n");
    yesorno = true;
    return;
}

void save_as(void)
{
    struct students *tmp;
    char str[20];

    printf("请输入保存的文件名:");
    gets(str);
    FILE *fp = fopen(str, "w");
    if (fp == NULL)
    {
        fprintf(stderr, "Can't build %s\n", str);
        exit(0);
    }
    for (tmp = student; tmp; tmp = tmp->next)
    {
        fprintf(fp, "%d\n%s\n%d\n%.1f\n%.1f\n%.1f\n", tmp->classes, tmp->name, tmp->number, tmp->math, tmp->chinese, tmp->english);
    }
    fclose(fp);
    printf("另存储完毕\n");
    yesorno = true;
    return;
}

void read(void)
{
    FILE *fp;

    if ((fp = fopen("studentsdata.txt", "r")) == NULL)
    {
        fprintf(stderr, "Can't open studentsdata.txt\n");
        exit(0);
    }

    for (;!feof(fp);)
    {
        struct students *tmp = malloc(sizeof(struct students));
        if (tmp == NULL)
        {
            fprintf(stderr, "No momory space.\n");
            return;
        }
        fscanf(fp, "%d\n", &tmp->classes);
        fscanf(fp, "%s\n", tmp->name);
        fscanf(fp, "%d\n%f\n%f\n%f\n",  &tmp->number, &tmp->math, &tmp->chinese, &tmp->english);
        tmp->next = student;
        student = tmp;
    }
    fclose(fp);
    printf("读取完成\n");
    yesorno = false;
    return;
}

void search(void)
{
    char code[20];
    struct students *tmp;
    printf("请输入您要查找的学生名字或学号:");
    gets(code);
    tmp = find(code);
    if (tmp != NULL)
    {
        printf("Students data:\n");
        printf("classes     name        number      math        chinese     english     \n");
        printf("%-12d%-12s%-12d%-12.1f%-12.1f%-12.1f\n", tmp->classes, tmp->name, tmp->number, tmp->math, tmp->chinese, tmp->english);
        printf("\n");
    }
    return;
}

void sort(void)//排序算法很粗糙,这是我自己的想出来的,改进也有,比如变成双链表,完成排序后销毁等
{
    char code, code1;
    bool x = true;
    printf("请选择排序关键字:学号(n),数学(m),语文(c):");//暂定3个,可继续添加
    
    scanf(" %c", &code);
    while (getchar() != '\n')
        ;
    printf("升级排序(u),降级排序(d):");
    scanf(" %c", &code1);
    while (getchar() != '\n')
        ;
    if (code1 == 'u')
    {
        if (code == 'n')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->number > cur->number)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)//保证student指向头
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)//保证调整位置前后指针连接
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;//只要进行了位置调整,x都为false,以保证继续循环
                    }
                }
                if (x)
                    break;
            }
        }
        if (code == 'm')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->math > cur->math)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;
                    }
                }
                if (x)
                    break;
            }
        }
        if (code == 'c')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->chinese > cur->chinese)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;
                    }
                }
                if (x)
                    break;
            }
        }
    }
    if (code1 == 'd')
    {
        if (code == 'n')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->number < cur->number)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;
                    }
                }
                if (x)
                    break;
            }
        }
        if (code == 'm')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->math < cur->math)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;
                    }
                }
                if (x)
                    break;
            }
        }
        if (code == 'c')
        {
            struct students *cur, *prev, *tmp;
            for (;;)
            {
                x = true;
                for (cur = student->next, prev = student; cur != NULL; prev = cur, cur = cur->next)
                {
                    if (prev->chinese < cur->chinese)
                    {
                        prev->next = cur->next;
                        cur->next = prev;
                        if (prev == student)
                            student = cur;
                        else {
                            for (tmp = student; tmp->next != prev; tmp = tmp->next)
                                ;
                            tmp->next = cur;
                        }
                        tmp = cur;
                        cur = prev;
                        prev = tmp;
                        x = false;
                    }
                }
                if (x)
                    break;
            }
        }
    }
    printf("排序完毕。\n");
    return;
}



[此贴子已经被作者于2017-2-18 00:17编辑过]

2017-02-13 23:44
lf1010849299
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2016-11-15
收藏
得分:0 
回复 3楼 yanzy
还缺清空函数,不知道该怎么写,还有
tmp->next = student;
    student = tmp;
    yesorno = false;
    return student;没看懂


[此贴子已经被作者于2017-2-18 15:04编辑过]

2017-02-18 13:50
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
收藏
得分:0 
void fun(struct student *student)
{
   struct student *p;
   
   while(student)
   {
      p = student;
      student = student->next;
      free(p)
    }
}

早知做人那么辛苦!  当初不应该下凡
2017-02-18 14:22
ConeC
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-2-18
收藏
得分:0 
很有用 也很感谢有人解答
2017-02-18 14:39
快速回复:编一个学生信息管理系统,求大神帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.098625 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved