C语言增删改查学生信息

该博客介绍了如何使用C语言进行学生信息的管理,包括统计不及格人数、增加、删除和显示所有学生信息的功能,并详细讲解了相关函数的实现和运行过程。
摘要由CSDN通过智能技术生成

功能说明

  1. 统计不及格人数
  2. 增加一条学生信息
  3. 删除一条学生信息
  4. 显示所有学生信息

函数实现

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

typedef struct {
    int num;
    char name[20];
    char sex;
    float score;
}stu;

/**
 * 返回不及格人数
 * @param boy 学生表
 * @param num
 * @return
 */
int IsFlunk(stu *boy,int num)
{
    int f=0;
    for (int i = 0; i < num; ++i) {
        if(boy[i].num !=0 && boy[i].score < 60)
            f++;
    }
    return f;
}

/**
 * 在指定位置之前插入学生信息
 * @param boy
 * @param num
 * @param cname
 * @param stu1
 */
void StuInsert(stu *boy,int num,char* cname,stu stu1)
{
    int a=0;
    for (int i = 0; i < num; ++i) {
        if(strcmp(boy[i].name, cname) == 0)
        {
            a=i;
            break;
        }
    }
    for (int i = a+1; i < num; ++i) {
        boy[i]=boy[i-1];
    }
    boy[a]=stu1;
}
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的学生信息管理系统的C语言示例,包括增加、删除、修改和查询功能: 1. 添加学生信息: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct student { char name[20]; char id[20]; int age; struct student *next; } stu; void Add(stu **head) { stu *newStu = (stu *)malloc(sizeof(stu)); printf("请输入学生的姓名:\n"); scanf("%s", newStu->name); printf("请输入学生的学号:\n"); scanf("%s", newStu->id); printf("请输入学生的年龄:\n"); scanf("%d", &(newStu->age)); newStu->next = NULL; if (*head == NULL) { *head = newStu; } else { stu *temp = *head; while (temp->next != NULL) { temp = temp->next; } temp->next = newStu; } printf("添加成功!\n"); system("pause"); } int main() { stu *head = NULL; Add(&head); return 0; } ``` 2. 删除学生信息: ```c void Delete(stu **head) { char n[20]; printf("请输入要删除的学生的学号:\n"); scanf("%s", n); stu *p = *head; stu *p1 = p->next; while (p1 != NULL) { while (strcmp(p1->id, n) == 0) { p->next = p1->next; free(p1); printf("删除成功!\n"); system("pause"); return; } p = p1; p1 = p->next; } if (p1 == NULL || strcmp(n, p1->id) != 0) { printf("没有该学生!\n"); system("pause"); } } ``` 3. 修改学生信息: ```c void Modify(stu *head) { char n[20]; printf("请输入要修改的学生的学号:\n"); scanf("%s", n); stu *p = head; while (p != NULL) { if (strcmp(p->id, n) == 0) { printf("请输入学生的新姓名:\n"); scanf("%s", p->name); printf("请输入学生的新年龄:\n"); scanf("%d", &(p->age)); printf("修改成功!\n"); system("pause"); return; } p = p->next; } printf("没有该学生!\n"); system("pause"); } ``` 4. 查询学生信息: ```c void Search(stu *head) { char n[20]; printf("请输入要查询的学生的学号:\n"); scanf("%s", n); stu *p = head; while (p != NULL) { if (strcmp(p->id, n) == 0) { printf("学生姓名:%s\n", p->name); printf("学生学号:%s\n", p->id); printf("学生年龄:%d\n", p->age); system("pause"); return; } p = p->next; } printf("没有该学生!\n"); system("pause"); } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值