c 编的学生个人消费管理系统

2008-02-23 05:32:31来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct scorenode)
#define DEBUG
#include <string.h>
struct scorenode
{int number;/*学号*/
char name[10];/*姓名*/
float xiaofei;/*消费情况*/
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;/*n,k为全局变量,本程式中的函数均能够使用他*/
/*==============================================================================================*/
score *creat2311(void)
/*函数creat2311,功能:创建链表,此函数带回一个指向链表头的指针*/
{
score*head;
score *p1,*p2,*p3,*max;
int i,j;
float fen;
char t[10];
n=0;
p1=p2=p3=(score *)malloc(LEN);head=p3; /*开辟一个新单元*/
printf("请输入学生资料,输0退出!\n");
repeat1: printf("请输入学生学号(学号应大于0):");/*输入学号,学号应大于0*/
scanf("%d",&p1->number);
while(p1->number<0)
{getchar();
printf("输入错误,请重新输入学生学号:");
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("学号重复,请重输!\n");
goto repeat1;
/*当输入的学号已存在,程式报错,返回前面重新输入*/
}
}
}
}
printf("请输入学生姓名:");
scanf("%s",&p1->name);/*输入学生姓名*/
printf("请输入消费情况:");/*输入消费情况;

head=NULL;
while(p1->number!=0)
{
n=n 1;
if(n==1)
head=p1;
else

p2->next=p1;
p2=p1;
p1=(score *)malloc(LEN);
printf("请输入学生资料,输0退出!\n");
repeat2:printf("请输入学生学号(学号应大于0):");
scanf("%d",&p1->number);/*输入学号,学号应大于0*/

while(p1->number<0)
{getchar();
printf("输入错误,请重新输入学生学号:");
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("学号重复,请重输!\n");
goto repeat2;
/*当输入的学号已存在,程式报错,返回前面重新输入*/
}
}
}
}
printf("请输入学生姓名:");
scanf("%s",&p1->name);/*输入学生姓名*/
printf("请输入消费情况:");
scanf("%f",&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("输入的学生数为:%d个!\n",n);
return(head);

}
/*==============================================================================================*/
/*==============================================================================================*/
score *load2311(score *head)
/*函数load2311,功能:从文档读入学生记录*/
{ score *p1,*p2;
int m=0;
char filepn[10];
FILE *fp;

printf("请输入文档路径及文档名:");
scanf("%s",filepn);/*输入文档路径及名称*/
if((fp=fopen(filepn,"r "))==NULL)
{
printf("不能打开文档!\n");
return 0;
}
{

p1=(score *)malloc(LEN); /*开辟一个新单元*/
fscanf(fp,"%d%s%f%f%f",&p1->number,p1->name,&p1->yuwen,&p1->yingyu,&p1->shuxue);
printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->yuwen,p1->yingyu,p1->shuxue);
/*文档读入和显示*/
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%f%f%f\n",&p1->number,p1->name,&p1->yuwen,&p1->yingyu,&p1->shuxue);
printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->yuwen,p1->yingyu,p1->shuxue);

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: c 编的学生个人消费管理系统(2)

下一篇: 怎样编制通讯录程式