#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include"stu_man_sys.h"
void scanf_stu_info(stu_lib **stu)
{
int i,len=0;
printf("请输入该学生的学号:");
while(1)
{
scanf("%s%*c",(*stu)->stu.ID);
len=strlen((*stu)->stu.ID);
for(i=0;i<len;i++)
{
if(isspace((*stu)->stu.ID[i]) || !(isdigit((*stu)->stu.ID[i])))
{
break;
}
}
if(i==len)
break;
printf("您的输入有问题,请再输入:");
}
len=0;
printf("请再输入姓名:");
while(1)
{
scanf("%s%*c",(*stu)->stu.name);
len=2*strlen((*stu)->stu.name);
for(i=0;i<len;i++)
if(isdigit((*stu)->stu.name[i]))
{
break;
}
if(i== len)
break;
printf("您的输入有问题,请再输入:");
}
printf("请输入其各科成绩。\n");
printf("计算机:");
while(1)
{
scanf("%f%*c",&(*stu)->stu.scores[0]);
if((*stu)->stu.scores[0] >= 0 && (*stu)->stu.scores[0] <= 10000)
{
printf("输入正确!\n");
break;
}
printf("请重输:");
}
printf("高等数学:");
while(1)
{
scanf("%f%*c",&(*stu)->stu.scores[1]);
if((*stu)->stu.scores[1] >= 0 && (*stu)->stu.scores[1] <= 10000)
{
printf("输入正确!\n");
break;
}
printf("请重输:");
}
printf("经济法:");
while(1)
{
scanf("%f%*c",&(*stu)->stu.scores[2]);
if((*stu)->stu.scores[2] >=0 && (*stu)->stu.scores[2] <= 10000)
{
printf("输入正确!\n");
break;
}
printf("请重输:");
}
}
void creat_stu_lib(stu_lib **headp,int n)
{
stu_lib *pnew,*qnew;
int count;
printf("下面开始创建一个包含%d个元素的无序的链表!\n",n);
for(count=0;count<n;count++)
{
pnew=(stu_lib *)malloc(sizeof(stu_lib));
scanf_stu_info(&pnew);
pnew->next=NULL;
if(NULL == *headp)
*headp=pnew;
else
qnew->next=pnew;
qnew=pnew;
}
}
void print_stu_info(stu_lib *headp)
{
long int stu_ID=0;
if(NULL == headp)
printf("\n");
else
{
stu_ID=atoi(headp->stu.ID);
printf("%ld\t%s\t%f\t%f\t%f\t\n",stu_ID,headp->stu.name,headp->stu.scores[0],headp->stu.scores[1],headp->stu.scores[2]);
print_stu_info(headp->next);
}
}
void sort_stu_lib(stu_lib **headp)
{
stu_lib *p,*q,*tmp;
tmp=(stu_lib *)malloc(sizeof(stu_lib));
p=*headp;
if(NULL == *headp)
{
printf("这是一个空链表!\n");
free(tmp);
return ;
}
else
if(NULL != (*headp)->next)
{
q=p->next;
while(1)
{
while(1)
{
if(atoi(p->stu.ID) > atoi(q->stu.ID))
{
memcpy(tmp->stu.ID,p->stu.ID,100*sizeof(char));
memcpy(tmp->stu.name,p->stu.name,100*sizeof(char));
memcpy(tmp->stu.scores,p->stu.scores,3*sizeof(float));
memcpy(p->stu.ID,q->stu.ID,100*sizeof(char));
memcpy(p->stu.name,q->stu.name,100*sizeof(char));
memcpy(p->stu.scores,q->stu.scores,3*sizeof(float));
memcpy(q->stu.ID,tmp->stu.ID,100*sizeof(char));
memcpy(q->stu.name,tmp->stu.name,100*sizeof(char));
memcpy(q->stu.scores,tmp->stu.scores,3*sizeof(float));
}
if(NULL == q->next)
break;
q=q->next;
}
p=p->next;
if(NULL == p->next)
break;
q=p;
}
free(tmp);
}
else
{
printf("该链表就一个节点,无需排序!\n");
free(tmp);
return ;
}
}
void search_stu_info(stu_lib **headp,char *S_ID)
{
stu_lib *head;
if(NULL != *headp)
{
head=*headp;
while(1)
{
if(0 == strcmp(S_ID ,head->stu.ID))
{
printf("%s\t%s\t%f\t%f\t%f\t\n",S_ID,head->stu.name,head->stu.scores[0],head->stu.scores[1],head->stu.scores[2]);
return;
}
if(NULL == head->next)
break;
head=head->next;
}
printf("无此学生!\n");
return ;
}
else
{
printf("这是个空链表!\n");
return ;
}
}
void insert_stu_info(stu_lib **headp,stu_lib *new_stu,int pos)
{
stu_lib *head,*tmp;
int i=1;
int num=1,count=5;
if(NULL != *headp)
{
head=*headp;
tmp=*headp;
while(NULL != tmp->next)
{
num++;
tmp=tmp->next;
}
while(count--)
{
if( (pos <= 0) || (pos > num) )
{
printf("您插入的位置有误,您还有%d次机会,请重新输入插入的位置:",count);
scanf("%d%*c",&pos);
}
else
break;
}
if(count == 0)
{
printf("你是猪啊,五次都不行!\n");
return ;
}
while(NULL != head->next && i < pos)
{
tmp=head;
head=head->next;
i++;
}
if(i==pos)
{
if(*headp == head)
{
new_stu->next=head;
*headp=new_stu;
}
else
{
new_stu->next=head;
tmp->next=new_stu;
}
}
}
else
{
*headp=new_stu;
new_stu->next=NULL;
}
return ;
}
void delelet_stu_info(stu_lib **headp,char *S_ID)
{
stu_lib *forward,*after;
if(NULL == S_ID)
{
printf("您没有输入要删除的学生学号!\n");
return ;
}
if(NULL != *headp)
{
after=*headp;
while(NULL != after->next && strcmp(S_ID ,after->stu.ID))
{
forward=after;
after=after->next;
}
if(0 == strcmp(S_ID ,after->stu.ID))
{
if(*headp == after)
*headp=after->next;
else
forward->next=after->next;
free(after);
printf("该学生的档案删除成功!\n");
return ;
}
else
{
printf("无学号为%s的学生!\n",S_ID);
return ;
}
}
else
{
printf("该档案为空!\n");
return ;
}
}
void destory_stu_lib(stu_lib **headp)
{
if(NULL != *headp)
{
while(NULL != (*headp)->next)
{
stu_lib *tmp;
tmp=*headp;
*headp=(*headp)->next;
free(tmp);
}
free(*headp);
printf("学生档案库销毁成功!\n");
return ;
}
else
{
printf("该档案库为空,无需销毁操作!\n");
return ;
}
}
int main()
{
stu_lib *headp=NULL;
stu_lib *new_stu;
int n,pos;
char S_ID[100];
char ch;
printf("请输入要创建链表的元素个数:");
scanf("%d%*c",&n);
creat_stu_lib(&headp,n);
printf("想要插入新学生吗:");
scanf("%c%*c",&ch);
switch(ch)
{
case 'y':
case 'Y':
new_stu=(stu_lib *)malloc(sizeof(stu_lib));
if(NULL == new_stu)
{
printf("为新学生分配档案存贮空间失败!\n");
break;
}
scanf_stu_info(&new_stu);
printf("请输入您想插入的位置:");
scanf("%d%*c",&pos);
insert_stu_info(&headp,new_stu,pos);
break;
default:
break;
}
print_stu_info(headp);
sort_stu_lib(&headp);
print_stu_info(headp);
printf("需要查询吗:");
scanf("%c%*c",&ch);
switch(ch)
{
case 'y':
case 'Y':
printf("请输入学号:");
scanf("%s%*c",S_ID);
search_stu_info(&headp,S_ID);
break;
default:
break;
}
ch=' ';
printf("需要删除某个学生吗:");
scanf("%c%*c",&ch);
switch(ch)
{
case 'y':
case 'Y':
printf("请输入学号:");
scanf("%s%*c",S_ID);
delelet_stu_info(&headp,S_ID);
print_stu_info(headp);
break;
default:
break;
}
destory_stu_lib(&headp);
return 0;
}
stu_man_sys.zip_mansyscom_www. mean sys. com
版权申诉
7 浏览量
2022-09-24
02:34:23
上传
评论
收藏 247KB ZIP 举报
alvarocfc
- 粉丝: 105
- 资源: 1万+
最新资源
- database-project-massunaAi笔记
- 2%EF%BC%9A%E9%99%95%E8%A5%BF%E
- yyspdz62_944.apk
- SAP公司间采购EDI配置-如何触发自动MIRO.docx
- python197基于图像识别的仪表实时监控系统.rar
- python196基于循环神经网络的情感分类系统.rar
- I2C驱动SHT30温湿度传感器和LCD12864使用例程(RSCG12864B)
- python193中学地理-中国的江河湖泊教学网(django).rar
- python191基于时间序列分析的大气污染预测软件(django).rar
- python190基于人脸识别智能化小区门禁管理系统.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0