简易学生管理系统。。。。

      简易学生管理系统这里使用的是单链表,简单的实现添加姓名,学号,分数,以及删除,显示添加的信息。

#include<stdio.h>

#include<stdlib.h>

struct node

{

  char name[100];

  int num;

  float grade;

  struct node *next;

};

struct node *head;

struct node *last;

void cre_list()

{

  head = (struct node *)malloc(sizeof(struct node));

  head->next = NULL;

  last = head; 

}

void add_node()

{

  struct node *ptr = (struct node *)malloc(sizeof(struct node));

  printf("输入姓名:\n");

  scanf("%s",&ptr->name);

  printf("输入学号:\n");

  scanf("%d",&ptr->num);

  printf("输入成绩:\n");

  scanf("%f",&ptr->grade);

  last->next = ptr;

  ptr->next = NULL;

  last = ptr;

}

void display_node()

{

  struct node *ptr = head->next;

  while(ptr != NULL)

  {

    printf("姓名:%s\t",ptr->name);

    printf("学号:%d\t",ptr->num);

    printf("成绩:%f\t",ptr->grade);

    ptr = ptr->next;

  }

}

void find_node()

{

  struct node *ptr = head;

  char p[100];

  printf("输入查找的学生姓名:\n");

  scanf("%s",p);

  while(strcmp(ptr->name,p)!= 0)

  {

    ptr = ptr->next;

    if(ptr == NULL)

    {

      printf("不存在此学生\n");

    }

   printf("姓名:%s\t学号:%d\t成绩:%f\n",ptr->name,ptr->num,ptr->grade);

  }

}

void delete_node()

{

  struct node *ptr = head;

  struct node *str = head;

  int i;

  printf("输入删除的学号:\n");

  scanf("%d",&i);

  while(ptr->num != i)

  {

    str = ptr;

    ptr = ptr->next;

    if(ptr == NULL)

    {

      printf("没有此学生\n");

    }

  }

   ptr = str->next;

   str->next = ptr->next;

   free(ptr);

   printf("已经删除\n");

}

void clear()

{

    char c;

    while((c = getchar()) != '\n' && c != EOF)

    {

        ;

    }

}

int main()

{

  printf("a:初始\t,b:添加\n");

  printf("c:显示\t, d:查找\n");

  printf("e:删除\t, f退出");

  while(1)

  {

   printf("please input:\n");

   char j;

   scanf("%c",&j);

   switch(j)

   {

     case'a':

     cre_list();

     printf("初始化完成\n");

     break;

     case 'b':

     add_node();

     printf("已经添加\n");

     break;

     case'c':

     display_node();

     break;

     case'd':

     find_node();

     break;

     case'e':

     delete_node();

     break;

     case'f':

     exit(0);

     default:

     break;

   }

     clear();

  }

  return 0;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值