C语言模拟学生管理系统链表学习

C语言的链表学习,以前刚学习C语言的时候是写的。里面存在的很多不足,放这里做个记录。能对刚学习的道友有帮助就更好,老道友们欢迎指出错误。

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

struct stu
{
unsigned int xh;
unsigned char name[10];
unsigned char ywcj;
unsigned char sxcj;
unsigned char yycj;
unsigned char pjcj;
unsigned int zcj;
struct stu *next;

}*head;


struct stu *creat(unsigned char n);
void cx(struct stu *head,unsigned int xh);
struct stu *dele(struct stu *head,unsigned int xh);
struct stu *sr(struct stu *head);
void xs(struct stu *head);


main()
{
unsigned char k;
unsigned int g;
while(1)
{
printf("**********************************\n");
printf("         1.成绩录入               \n");
printf("         2.查询信息               \n");
printf("         3.删除信息               \n");
printf("         4.插入信息               \n");
printf("         5.显示信息               \n");
printf("**********************************\n");
printf("请选择你的操作 ");
scanf("%d",&k);

switch(k)
{
case 1:
head=creat(6);break;
case 2:
printf("请输入你要查找的学号");
scanf("%d",&g);
cx(head,g);
break;


case 3:
printf("请输入你要删除的学号");
scanf("%d",&g);
head=dele(head,g);
break;
case 4:head=sr(creat(1));
break;
case 5:xs(head);break;

default:;

}


}

}


struct stu *creat(unsigned char n)
{
struct stu *pb,*head,*pf;
unsigned char i;


for(i=0;i<n;i++)
{
pb=(struct stu*)malloc(sizeof(struct stu));

printf("请输入学号 ");
scanf("%s",&pb->xh);

printf("请输入姓名 ");
scanf("%s",&pb->name);


printf("请输入语文成绩 ");
scanf("%d",&pb->ywcj);

printf("请输入数学成绩 ");
scanf("%d",&pb->sxcj);

printf("请输入英语成绩 ");
scanf("%d",&pb->yycj);

printf("请输入平均成绩 ");
scanf("%d",&pb->pjcj);

printf("请输入总成绩 ");
scanf("%d",&pb->zcj);
printf("_______________________\n");


if(i=0)
{
head=pb=pf;
}

else
{
pb->next=pb;
}

pf=pb;


}

return head;

}


void cx(struct stu *head,unsigned int xh)
{
struct stu *p;
p=head;

while(p->xh!=xh&&p->next!=0)
{
p=p->next;

}

if(p!=0)
{
printf("该学生的信息如下\n");

printf("学号: %d\n",p->xh);
printf("姓名: %s\n",p->name);
printf("语文成绩: %d\n",p->ywcj);
printf("数学成绩: %d\n",p->sxcj);
printf("英语成绩: %d\n",p->yycj);
printf("平均成绩: %d\n",p->pjcj);
printf("总成绩: %d",p->zcj);

}

else
{
printf("没有找到该学号学生的信息");

}

}


struct stu *dele(struct stu *head,unsigned int xh)
{
struct stu *p,*pf;
p=head=pf;

while(p->xh!=xh&&p->next!=0)
{
pf=p;
p=p->next;

}


if(p!=0)
{
if(p=head)
{
head=p->next;

}

else
{
pf->next =p->next ;

}
}

else
{
printf("没有找到符合条件的学生");
}

 return head;


}


struct stu *sr(struct stu *head)
{
struct stu *p;
p->next=head;
p=head;
return head;
}

void xs(struct stu *head)
{
struct stu *p;
p=head;

while(p!=0)
{

printf("------------------------------------");
printf("学号: %d\n",p->xh);
printf("姓名: %s\n",p->name);
printf("语文成绩: %d\n",p->ywcj);
printf("数学成绩: %d\n",p->sxcj);
printf("英语成绩: %d\n",p->yycj);
printf("平均成绩: %d\n",p->pjcj);
printf("总成绩: %d",p->zcj);
p=p->next;

}


}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值