学生管理系统

系统代码实现如下:

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #define MAX 100
 
 struct student
 {
     int age;
     char name[50];
     int id;
 };
 void add_stu(struct student arr[],int *count,int max);
 void show_stu(struct student arr[],int count);
 void del_stu(struct student arr[],int *count);
 void find_stu(struct student arr[],int count);
 void mod_stu(struct student arr[],int count);
 
 int main(int argc, const char *argv[])
 {
     int count = 0;
     struct student arr[MAX];
     add_stu(arr,&count,MAX);
     add_stu(arr,&count,MAX);
     add_stu(arr,&count,MAX);
     add_stu(arr,&count,MAX);
     show_stu(arr,count);
     del_stu(arr,&count);
     show_stu(arr,count);
     find_stu(arr,count);
     mod_stu(arr,count);
     show_stu(arr,count);                                                                                                                                                                                                                     
     return 0;
 }
 void add_stu(struct student arr[],int *count,int max)
 {
     if(*count >= max)
     {
         printf("已达到学生数量的上限\n");
         return;
     }
     printf("请输入学生姓名:\n");
     scanf("%s",arr[*count].name);
     printf("请输入学生的年龄:\n");
     scanf("%d",&(arr[*count].age));
     printf("请输入学生的学号\n");
     scanf("%d",&(arr[*count].id));
 
     (*count)++;
 }
 
 void show_stu(struct student arr[],int count)
 {
     printf("学生信息打印如下\n");
     for(int i=0;i<count;i++)
     {
         printf("姓名:%s 年龄:%d  学号:%d\n",arr[i].name,arr[i].age,arr[i].id);
 
     }
 }
 
 void del_stu(struct student arr[],int *count){
     printf("请输入要删除学生的学号:\n");
     int del_id;
     scanf("%d",&del_id);
     for(int i=0;i<(*count);i++){
         if(arr[i].id==del_id){
             (*count)--;
             for(int j=i;j<(*count);j++)
             {
                 arr[j]=arr[j+1];
             }
             break;
         }
     }
 }
 
 void find_stu(struct student arr[],int count){
     int stu_id;
     printf("请输入你要查找学生的位数:\n");
     scanf("%d",&stu_id);
     if(stu_id<0 || stu_id>count){
         printf("输入位置无效,请重新输入\n");
         return;
     }
     printf("该学生的姓名为:%s  ",arr[(stu_id-1)].name);
     printf("年龄:%d  ",arr[(stu_id-1)].age);
     printf("学号:%d\n",arr[(stu_id-1)].id);
 }
 
 void mod_stu(struct student arr[],int count){
     int stu_id;
     printf("请输入你要修改学生的位数:\n");
     scanf("%d",&stu_id);
     if(stu_id<0 || stu_id>count){
         printf("输入位置无效,请重新输入\n");
         return;
     }
     printf("请输入学生修改后的姓名:\n");
     scanf("%s",arr[(stu_id-1)].name);
     printf("请输入学生修改后的年龄:\n");
     scanf("%d",&(arr[(stu_id-1)].age));
     printf("请输入修改后学生的学号\n");
     scanf("%d",&(arr[(stu_id-1)].id));
 }
                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                            

运行结果如下:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值