编写的简单程序无法运行

学生成绩管理系统设计 学生成绩信息包括:学号、姓名、C语言等课程成绩。试设计一选修课程系统,使 之能提供以下功能:系统以菜单方式工作(用键盘输入16之间的数来选择功能) (1)成绩信息录入功能(成绩信息用文件保存) (2)成绩信息浏览功能 (3)查询功能:按学号查询和按成绩段查询 (4)成绩信息的删除:按学号进行删除某学生的成绩 (5)成绩信息的修改:按成绩修改,把5559分之间的成绩都加上5分 (6)退出。

img

img

img

img

img

img

img

img

img

你什么编辑器:

img

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//定义学生信息结构体
struct student {
    char id[20];
    char name[20];
    float c_score;
    struct student* next;
};

//打印菜单
void print_menu() {
    printf("======学生成绩管理系统======\n");
    printf("1.成绩信息录入\n");
    printf("2.成绩信息浏览\n");
    printf("3.查询功能\n");
    printf("4.成绩信息删除\n");
    printf("5.成绩信息修改\n");
    printf("6.退出\n");
    printf("请输入您的选项:");
}

//添加学生信息
void add_student(struct student** head) {
    struct student* p = *head;
    struct student* node = (struct student*)malloc(sizeof(struct student));
    printf("请输入学号、姓名、C语言成绩:");
    scanf("%s%s%f", node->id, node->name, &(node->c_score));
    node->next = NULL;
    if (*head == NULL) {
        *head = node;
    }
    else {
        while (p->next != NULL)
            p = p->next;
        p->next = node;
    }
    printf("录入成功!\n");
}

//浏览学生信息
void browse_students(struct student* head) {
    struct student* p = head;
    if (p == NULL)
        printf("学生信息为空!\n");
    else {
        printf("学号\t姓名\tC语言成绩\n");
        while (p != NULL) {
            printf("%s\t%s\t%.2f\n", p->id, p->name, p->c_score);
            p = p->next;
        }
    }
}

//按学号查询学生信息
void query_by_id(struct student* head) {
    char id[20];
    struct student* p = head;
    printf("请输入学号:");
    scanf("%s", id);
    while (p != NULL && strcmp(p->id, id) != 0)
        p = p->next;
    if (p == NULL)
        printf("未找到该学生信息!\n");
    else {
        printf("学号\t姓名\tC语言成绩\n");
        printf("%s\t%s\t%.2f\n", p->id, p->name, p->c_score);
    }
}

//按成绩段查询学生信息
void query_by_score(struct student* head) {
    float min_score, max_score;
    struct student* p = head;
    int found = 0;
    printf("请输入成绩段(最小成绩和最大成绩以空格分隔):");
    scanf("%f%f", &min_score, &max_score);
    printf("学号\t姓名\tC语言成绩\n");
    while (p != NULL) {
        if (p->c_score >= min_score && p->c_score <= max_score) {
            printf("%s\t%s\t%.2f\n", p->id, p->name, p->c_score);
            found = 1;
        }
        p = p->next;
    }
    if (!found)
        printf("未找到符合条件的学生信息!\n");
}

//按学号删除学生信息
void delete_student(struct student** head) {
    char id[20];
    struct student* p = *head, * tmp;
    printf("请输入学号:");
    scanf("%s", id);
    if (*head == NULL) {
        printf("学生信息为空!\n");
        return;
    }
    if (strcmp((*head)->id, id) == 0) {
        tmp = *head;
        *head = (*head)->next;
        free(tmp);
        printf("删除成功!\n");
        return;
    }
    while (p->next != NULL && strcmp(p->next->id, id) != 0)
        p = p->next;
    if (p->next == NULL)
        printf("未找到该学生信息!\n");
    else {
        tmp = p->next;
        p->next = tmp->next;
        free(tmp);
        printf("删除成功!\n");
    }
}

// 修改成绩
void modify_score(struct student* head) {
    int min, max;
    struct student* p = head;
    printf("输入修改的成绩段:");
    scanf("%d%d", &min, &max);
    while (p != NULL) {
        if (p->c_score >= min && p->c_score <= max) {
            p->c_score += 5;
        }
        p = p->next;
    }
    printf("修改成功!\n");
}

int main() {
    struct student* head = NULL;
    int option = 0;
    int query_option;
    do {
        print_menu();
        scanf("%d", &option);
        switch (option) {
        case 1:
            add_student(&head);
            break;
        case 2:
            browse_students(head);
            break;
        case 3:
            printf("1按学号查询\n2按成绩段查询\n");
            printf("请输入您的选项:");
           
            scanf("%d", &query_option);
            if (query_option == 1)
                query_by_id(head);
            else if (query_option == 2)
                query_by_score(head);
            else
                printf("无效选项!\n");
            break;
        case 4:
            delete_student(&head);
            break;
        case 5:
            modify_score(head);
            break;
        case 6:
            printf("谢谢使用!\n");
            break;
        default:
            printf("无效选项!\n");
            break;
        }
    } while (option != 6);
    return 0;
}


稍等我调试一下,代码是自己写的吗?c++6.0环境下也是正常的,代码有很多指针指向错误,已经修改

img

img

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student
{
    char id[20];
    char name[20];
    float c_score;
    struct student *next;
};

void print_menu()
{
    printf("=====学生成绩管理系统====\n");
    printf("1.成绩信息录入\n");
    printf("2.成绩信息浏览\n");
    printf("3.查询功能入\n");
    printf("4.成绩信息删除\n");
    printf("5.成绩信息修改\n");
    printf("6.退出\n");
    printf("请输入您的选项:");
}

void add_student(struct student **head)
{
    struct student *p = *head;
    struct student *node = (struct student*)malloc(sizeof(struct student));
    printf("请输入学号、姓名、c语言成绩:");
    scanf("%s %s %f", node->id, node->name, &(node->c_score));
    node->next = NULL;
    if (*head == NULL)
    {
        *head = node;
    }
    else
    {
        while (p->next != NULL)
        {
            p = p->next;
        }
        p->next = node;
    }
    printf("录入成功!\n");
}

void browse_student(struct student *head)
{
    struct student *p = head;
    char id[20];
    printf("请输入学号:");
    scanf("%s", id);
    while (p != NULL && strcmp(p->id, id) != 0)
    {
        p = p->next;
    }
    if (p == NULL)
    {
        printf("未找到学生信息!\n");
    }
    else
    {
        printf("学号\t姓名\tC语言成绩\n");
        printf("%s\t%s\t%.2f\n", p->id, p->name, p->c_score);
    }
}

void query_by_score(struct student *head)
{
    float min_score, max_score;
    int found = 0;
    printf("请输入成绩段:");
    scanf("%f %f", &min_score, &max_score);
    printf("学号\t姓名\tC语言成绩\n");
    struct student *p = head;
    while (p != NULL)
    {
        if (p->c_score >= min_score && p->c_score <= max_score)
        {
            printf("%s\t%s\t%.2f\n", p->id, p->name, p->c_score);
            found = 1;
        }
        p = p->next;
    }
    if (!found)
    {
        printf("未找到符合条件的学生信息!\n");
    }
}

void delete_student(struct student **head)
{
    char id[20];
    struct student *p = *head, *tmp;
    printf("请输入学号:");
    scanf("%s", id);
    if (*head == NULL)
    {
        printf("学生信息为空!\n");
        return;
    }
    if (strcmp((*head)->id, id) == 0)
    {
        tmp = *head;
        *head = (*head)->next;
        free(tmp);
        printf("删除成功!\n");
        return;
    }
    while (p->next != NULL && strcmp(p->next->id, id) != 0)
    {
        p = p->next;
    }
    if (p->next == NULL)
    {
        printf("未找到该学生信息!\n");
    }
    else
    {
        tmp = p->next;
        p->next = tmp->next;
        free(tmp);
        printf("删除成功!\n");
    }
}

void modify_score(struct student *head)
{
    float min, max;
    int query_option;
    printf("输入修改得成绩段:");
    scanf("%f %f", &min, &max);
    struct student *p = head->next;
    while (p != NULL)
    {
        if (p->c_score >= min && p->c_score <= max)
        {
            p->c_score += 5;
        }
        p = p->next;
    }
    printf("修改成功!\n");
}

int main()
{
    struct student *head = NULL;
    int option = 0;
    do
    {
        print_menu();
        scanf("%d", &option);
        switch (option)
        {
            case 1:
                add_student(&head);
                break;
            case 2:
                browse_student(head);
                break;
            case 3:
                printf("1按学号查询\n2按成绩段查询\n");
                printf("请输入您的选项:");
                int query_option;
                scanf("%d", &query_option);
                if (query_option == 1)
                {
                    browse_student(head);
                }
                else if (query_option == 2)
                {
                    query_by_score(head);
                }
                else
                {
                    printf("无效选项!\n");
                }
                break;
            case 4:
                delete_student(&head);
                break;
            case 5:
                modify_score(head);
                break;
            case 6:
                printf("谢谢使用!\n");
                break;
            default:
                printf("无效选项!\n");
                break;
        }
    } while (option != 6);
    return 0;
}


能贴出来吗

1我看看

贴源码吧?另外,什么问题?