学生信息管理系统制作

学生信息管理基本业务活动包括:对一个学生基本信息的输入、输出、查询、删除、插入等等。试设计一个学生信息管理系统,将上述业务活动借助于计算机系统完成。
【基本要求】:要输出相应界面:链式存储方法实现。
〈1〉每个学生的信息包括:学号、姓名、性别、籍贯、电话
〈2〉系统应实现的操作及其功能定义如下:
输入:
② 查找:
③ 插入:
④删除:
⑤统计各生源地的人数:
显示:
【测试数据】
录入学生学号:180101 180102 180103 180104 180105 180106 180107 180109 插入180108 然后清除180102 180104 其余数据自行设计。

代码截图:

img

img

img

img

代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _student
{
    int id; //学号
    char name[40]; //姓名
    char sex[8]; //性别
    char addr[100]; //籍贯
    char phone[12]; //电话
}Student;

typedef struct _node
{
    Student data;
    struct _node* next;
}LinkNode;

// 创建链表
LinkNode* CreateList()
{
    LinkNode* p = (LinkNode*)malloc(sizeof(LinkNode));
    p->next = 0;
    return p;
}

// 录入
LinkNode* AddList(LinkNode* head)
{
    LinkNode* p, * t;
    t = (LinkNode*)malloc(sizeof(LinkNode));
    t->next = 0;

    system("cls");
    printf("请输入需要录入的学生的学号:");
    scanf("%d", &t->data.id);
    printf("请输入需要录入的学生的姓名:");
    scanf("%s", t->data.name);
    printf("请输入需要录入的学生的性别:");
    scanf("%s", t->data.sex);
    printf("请输入需要录入的学生的籍贯:");
    scanf("%s", t->data.addr);
    printf("请输入需要录入的学生的手机号:");
    scanf("%s", t->data.phone);

    //移动到链表尾部
    p = head;
    while (p->next)
        p = p->next;
    p->next = t;

    printf("插入成功!\n");
    system("pause");
    return head;
}

//插入
LinkNode* InertList(LinkNode* head)
{
    LinkNode* p, * t;
    int pos, i;
    system("cls");


    t = (LinkNode*)malloc(sizeof(LinkNode));;
    t->next = 0;
    

    printf("请输入需要插入的学生的学号:");
    scanf("%d", &t->data.id);
    printf("请输入需要插入的学生的姓名:");
    scanf("%s", t->data.name);
    printf("请输入需要插入的学生的性别:");
    scanf("%s", t->data.sex);
    printf("请输入需要插入的学生的籍贯:");
    scanf("%s", t->data.addr);
    printf("请输入需要插入的学生的手机号:");
    scanf("%s", t->data.phone);

    printf("请输入插入位置:");
    scanf("%d", &pos);

    
    //移动到链表尾部
    p = head->next;
    i = 1;
    while (p && i < pos-1) 
    {
        p = p->next;
        i++;
    }
    if (p)
    {
        t->next = p->next;
        p->next = t;
        printf("插入成功!\n");
    }
    else
    {
        printf("插入位置不合适,插入失败!\n");
        free(t);
        t = 0;
    }

    
    system("pause");
    return head;
}

// 查找
void Search(LinkNode* head)
{
    char name[40];
    int id,op;
    int flag = 1;
    LinkNode* p;
    while (flag)
    {
        system("cls");

        printf("1.根据学号查找\n");
        printf("2.根据姓名查找\n");
        printf("3.结束查找\n");
        scanf("%d", &op);
        switch (op)
        {
        case 1:
            printf("请输入学号:");
            scanf("%d", &id);
            p = head->next;
            while (p)
            {
                if (p->data.id == id)
                {
                    printf("%d %s %s %s %s\n", p->data.id, p->data.name, p->data.sex, p->data.addr, p->data.phone);
                    break;
                }
                p = p->next;
            }
            if (p == 0)
                printf("未找到该学号的学生\n");
            break;
        case 2:
            printf("请输入姓名:");
            scanf("%s", name);
            p = head->next;
            while (p)
            {
                if (strcmp(p->data.name, name) == 0)
                {
                    printf("%d %s %s %s %s\n", p->data.id, p->data.name, p->data.sex, p->data.addr, p->data.phone);
                    break;
                }
                p = p->next;
            }
            if (p == 0)
                printf("未找到该学号的学生\n");
            break;
        case 3:
            flag = 0;
            break;
        }
        system("pause");
    }
}

// 删除
LinkNode* DeleteNode(LinkNode* head)
{
    LinkNode* pre, * p;
    int id;
    int flag = 0;
    system("cls");
    printf("请输入需要删除的学生学号:");
    scanf("%d", &id);
    pre = head;
    p = head->next;
    while (p)
    {
        if (p->data.id == id)
        {
            pre->next = p->next;
            free(p);
            printf("删除成功!\n");
            flag = 1;
            break;
        }
        else
        {
            pre = p;
            p = p->next;
        }
    }
    if (flag == 0)
        printf("查无此人\n");
    system("pause");
    return head;
}
//遍历链表
void showAll(LinkNode* head)
{
    LinkNode* p = head->next;
    while (p)
    {
        printf("%d %s %s %s %s\n", p->data.id, p->data.name, p->data.sex, p->data.addr, p->data.phone);
        p = p->next;
    }
}

//统计
void Tongji(LinkNode* head)
{
    char add[200][40];
    int nmb[200];
    int i, n = 0;
    LinkNode* p = head->next;
    system("cls");
    while (p)
    {
        for (i = 0; i < n; i++)
        {
            if (strcmp(p->data.addr, add[i]) == 0)
            {
                nmb[i] += 1;
                break;
            }
        }
        if (i == n)
        {
            strcpy(add[n], p->data.addr);
            nmb[n] = 1;
            n++;
        }
        p = p->next;
    }
    //输出统计结果
    printf("生源地统计结果:\n");
    for (i = 0; i < n; i++)
    {
        printf("%s %d\n", add[i], nmb[i]);
    }
    system("pause");
}

int main()
{
    int flag = 1, op;
    LinkNode* head=0;
    //创建链表
    head = CreateList();
    while (flag)
    {
        system("cls");
        printf("1.录入学生信息\n");
        printf("2.插入学生信息\n");
        printf("3.查找学生信息\n");
        printf("4.删除学生信息\n");
        printf("5.遍历学生信息\n");
        printf("6.统计生源地\n");
        printf("0.退出\n");
        scanf("%d",&op);
        switch (op)
        {
        case 1:
            head = AddList(head);
            break;
        case 2:
            head = InertList(head);
            break;
        case 3:
            Search(head);
            break;
        case 4:
            head = DeleteNode(head);
            break;
        case 5:
            system("cls");
            showAll(head);
            system("pause");
            break;
        case 6:
            Tongji(head);
            break;
        case 0:
            flag = 0;
            break;
        }
    }
    


}


这个是利用单链表作为基础,也就是单链表的增删,利用结构体实现。我帮别人实现过一个管理系统,你可以参考,利用我给的建议来实现,如果不会的话,可以私聊问我。