/*#include <malloc.h>*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN sizeof(struct scorenode)
#define DEBUG
/* 【自学去】网站收集 http://www.zixue7.com */
struct scorenode
{int number;/*学号*/
char name[10];/*姓名*/
int xiaofei;/*消费情况*/
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;/*n,k为全局变量,本程序中的函数均可*p3以使用它*/
void menu();
score *creat(void);
score *load(score *head);
score *search(score *head);
score *del(score *head);
score *add(score *head,score *stu);
void print(score *head);
save(score *p1);
/*==============================================================================================*/
/*=========================创建链表,此函数带回一个指向链表头的指针=============================*/
score *creat(void)
{
score *head;
score *p1,*p2,*p3,*max;
int i,j;
char t[10];
n=0;
p1=p2=p3=(score *)malloc(LEN);/*head=p3; 开辟一个新单元*/
printf("please input student's information,input 0 exit!\n");
repeat1: printf("please input student's number(number>0):");/*输入学号,学号应大于0*/
scanf(" %d",&p1->number);
while(p1->number<0)
{
getchar();
printf("error,please input number again:");
scanf("%d",&p1->number);
}
/*输入学号为字符或小于0时,程序报错,提示重新输入学号*/
if(p1->number==0)
goto end;/*当输入的学号为0时,转到末尾,结束创建链表*/
else
{
p3=head;
if(n>0)
{
for(i=0;i<n;i++)
{
if(p1->number!=p3->number)
p3=p3->next;
else
{
printf("number repeate,please input again!\n");
goto repeat1;
/*当输入的学号已经存在,程序报错,返回前面重新输入*/
}
}
}
}
printf("please input student's name:");
scanf("%s",&p1->name);/*输入学生姓名*/
printf("please input student's consume money:");/*输入消费情况;*/
scanf("%d",&p1->xiaofei);
while(p1->number!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(score *)malloc(LEN);
printf("please input student's information,input 0 exit!\n");
repeat2:printf("please input student's number(number>0):");
scanf("%d",&p1->number);/*输入学号,学号应大于0*/
while(p1->number<0)
{getchar();
printf("error,please input number again:");
scanf("%d",&p1->number);}
/*输入学号为字符或小于0时,程序报错,提示重新输入学号*/
if(p1->number==0)
goto end;/*当输入的学号为0时,转到末尾,结束创建链表*/
else
{
p3=head;
if(n>0)
{for(i=0;i<n;i++)
{if(p1->number!=p3->number)
p3=p3->next;
else
{printf("number repeate,please input again!\n");
goto repeat2;
/*当输入的学号已经存在,程序报错,返回前面重新输入*/
}
}
}
}
printf("please input student's name:");
scanf("%s",&p1->name);/*输入学生姓名*/
printf("please input student's consume money:");
scanf("%d",&p1->xiaofei);/*输入消费情况; */
}
end: p1=head;
p3=p1;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
max=p1;
p1=p1->next;
if(max->number>p1->number)
{
k=max->number;
max->number=p1->number;
p1->number=k;
/*交换前后结点中的学号值,使得学号大者移到后面的结点中*/
strcpy(t,max->name);
strcpy(max->name,p1->name);
strcpy(p1->name,t);
/*交换前后结点中的姓名,使之与学号相匹配*/
/*交换前后结点中的消费情况,使之与学号相匹配*/
}
}
max=head;p1=head;/*重新使max,p指向链表头*/
}
p2->next=NULL;/*链表结尾*/
printf("input student's num:%d ge!\n",n);
getch();
return(head);
}
/*==============================================================================================*/
/*===========================从文件读入学生记录=================================================*/
score *load(score *head)
{
score *p1,*p2;
int m=0;
char filepn[10];
FILE *fp;
printf("please input file's postion and its name:");
scanf("%s",filepn);/*输入文件路径及名称*/
if((fp=fopen(filepn,"r+"))==NULL)
{
printf("can't open this file!\n");
getch();
return 0;
}
else
{
p1=(score *)malloc(LEN); /*开辟一个新单元*/
fscanf(fp,"%d%s%d\n",&p1->number,p1->name,&p1->xiaofei);
printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei);
/*文件读入与显示*/
head=NULL;
do
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(score *)malloc(LEN); /*开辟一个新单元*/
fscanf(fp,"%d%s%d\n",&p1->number,p1->name,&p1->xiaofei);
printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei);
/*文件读入与显示*/
}while(!feof(fp));
p2->next=p1;
p1->next=NULL;
n=n+1;
}
printf("-----------------------------------------\n");/*表格下线*/
getch();
fclose(fp);/*结束读入,关闭文件*/
return (head);
}
/*==============================================================================================*/
/*=====================查询学生消费=====================================================*/
score *search(score *head)
{
int number;
score *p1,*p2;
printf("input the student's number of searching:");
scanf("%d",&number);
getchar();
while(number!=0)
{
if(head==NULL)
{
printf("\n nobody information!\n");
return(head);
}
printf("-----------------------------------------\n");
printf("|number\t|name\t|consume\t \n");
printf("-----------------------------------------\n");/*打印表格域*/
p1=head;
while(number!=p1->number&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(number==p1->number)
{
printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei);
printf("-----------------------------------------\n");
}/*打印表格域*/
else
printf("%dthis student not exist!\n",number);
printf("input the student's number of searching:");
scanf("%d",&number);
getchar();
}
printf("already exit!\n");
getchar();
return(head);
}
/*==============================================================================================*/
/*=======================删除学生资料================================================*/
score *del(score *head)
{
score *p1,*p2;
int number;
printf("input the student's number of deleting(input 0 exit):");
scanf("%d",&number);
getchar();
while(number!=0)/*输入学号为0时退出*/
{
if(head==NULL)
{
printf("\nnobody information!\n");
return(head);
}
p1=head;
while(number!=p1->number&&p1->next!=NULL)
/*p1指向的不是所要找的首结点,并且后面还有结点*/
{
p2=p1;
p1=p1->next;
} /*p1后移一个结点*/
if(number==p1->number)
/*找到了*/
{
if(p1==head)
head=p1->next;
/*若p1指向的是首结点,把地二个结点地址赋予head*/
else
p2->next=p1->next;
/*否则将下一个结点地址 赋给前一结点地址*/
printf("delete number:%d\n",number);
n=n-1;
}
else
printf("%d student not exist!\n",number);
/*找不到该结点*/
printf("input the student's number of deleting:");
scanf("%d",&number);
getchar();
}
#ifdef DEBUG
printf("already exit\n");
#endif
printf("now how many students:%d ge!\n",n);
getch();
return(head);
}
/*==============================================================================================*/
/*==============================================================================================*/
score *add(score *head,score *stu)
{
score *p0,*p1,*p2,*p3,*max;
int i,j;
char t[10];
p3=stu=(score *)malloc(LEN);/*开辟一个新单元*/
printf("\ninput the student's information of adding!");
repeat4: printf("please input the student's number(number>0):");
scanf("%d",&stu->number);
/*输入学号,学号应大于0*/
while(stu->number<0)
{
getchar();
printf("error,please input number again:");
scanf("%d"

2013crazy
- 粉丝: 1091
- 资源: 2650
最新资源
- 基于Vue框架的bodalDown婚纱预约系统设计源码
- 基于Dart语言的最新电影资讯与移动开发博文整合设计源码
- 汽车Dugoff轮胎模型与Carsim联合仿真系统:深入探索垂向力计算与路感策略验证,汽车Dugoff轮胎模型与Carsim联合仿真:路感策略验证与力对比分析,汽车Dugoff轮胎模型,该simuli
- Python-base64图片互转-GUI工具
- 基于XLD和CAD的模板匹配与多形状OpenCV实现:C++与C#编程语言下的create-shape-model-xld技术详解 ,基于XLD与CAD图形的多模板匹配技术研究,OpenCV与C++/
- 基于Java_SpringBoot_Vue的简易自习室座位预约系统设计源码
- 基于Flutter的智能洗衣机动画模拟设计源码
- 基于PHP+Vue的口腔门诊管理收费系统设计源码
- 电磁感应式无线充电技术:基于Multisim仿真的原理图解析与优化研究,电磁感应原理下的无线充电技术:Multisim仿真原理图解析,电磁感应式无线充电 multisim仿真 原理图等等 ,电磁感应式
- 基于Vue框架的西安旅游攻略网站设计源码
- 基于JavaScript、CSS、HTML的网页评价系统设计源码
- 基于Vue框架的袋鼠妈妈信贷项目设计源码
- 智能型自适应剩余电流动作保护器的研究
- 自动化专业综合实验平台的设计
- 基于Python语言的会员核算系统设计源码
- Matlab在垂直泊车中应用的路径规划控制与纯跟综控制算法优化,基于Matlab的垂直泊车路径规划与纯跟踪控制算法研究,matlab垂直泊车的路径规划控制,纯跟综控制算法 ,核心关键词:Matlab
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


