没有来的及调试,请多多包涵:
这个程序的源代码有不少漏洞,正在修改之中,请提出批评指正,谢谢!!!
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#define N 3
#define increase 4
#define NULL 0
typedef struct stud
{
char name[15];
int age;
float score;
struct stud *next;
}L;/*定义表的类型*/
L*p,*that,*othernew,*x,*you,*head;
L * enter_record ()/*加入记录*/
{
int n,i=0;
float m;
L *new;
head=new=(L*)malloc(N*sizeof(L));
if(!new)
{
printf("failure for applying room!\n");
exit(0);
}
else
{
p=new;
while(i<N)
{
i++;
printf("please enter name:");
fflush(stdin);
gets(p->name);
printf("\n");
printf("enter age:");
fflush(stdin);
scanf("%d",&n);
printf("\n");
p->age=n;
printf("enter the score:");
fflush(stdin);
scanf("%f",&m);
p->score=m;
p=p->next;
}
}
return head;
}
L *show_record()/*显示记录*/
{
int c=1;
L *this;
printf("the records are:\n");
this=head;
while(this->next!=NULL)
{
printf("the %d th is:\n");
printf("the name is:%s\n",this->name);
printf("the age is:%d\n",this->age);
printf("the score is:%f\n");
this=this->next;
c++;
}
printf("the number of records is:%d",c);
return head;
}
L *delete_record()/*删除记录*/
{
int d;
printf("which one record do you want to delete?number:");
fflush(stdin);
scanf("%d",&d);
printf("\n");
if(d>N-1||d<0)
{
printf("error due to the wrong input!\n");
exit(0);
}
else
{
int e=1;
that=head;
while(that->next!=NULL&&e<d)
{
that=that->next;
e++;
}
that->next=that->next->next;
free(that->next);
printf("the record has been deleted!\n");
}
return head;
}
L * insert_record()/*加入新的记录*/
{
int y;
printf("where will you insert the new record?number:");
fflush(stdin);
scanf("%d",&y);
printf("\n");
if(y>=1&&y<=N)
{
int z=1,g,h;
x=head;
while(x->next!=NULL&&z<=N)
{
z++;
x=x->next;
}
othernew=(L*)malloc(sizeof(L));
x->next=othernew;
othernew=x->next->next;
printf("please input the name new record:%s\n",othernew->name);
scanf("%d",&g);
printf("enter the age:%d\n",g);
scanf("%d",&h);
printf("enter the score:%d\n",h);
printf("the new record has been save!\n");
printf("the new record is:\n");
printf("the name is:%s\n",othernew->name);
printf("the age is:%d\n",othernew->age);
printf("the score is:%d\n",othernew->score);
}
return head;
}
main()/*主函数*/
{
int n;
clrscr();
printf("welcome to the student mangement system:\n");
printf("============================================================================\n");/*功能菜单*/
printf("1. Enter students' records 2.show the all records\n");
printf("3.Delete some students' records 4.Insert new record");
printf("5.exit mangement system.\n");
printf("=============================================================================\n");
printf("please choose from 1 to 5.No:");
do
{
fflush(stdin);
scanf("%d",&n);
switch(n)
{
case 1:
head=enter_record ();
break;
case 2:
head=show_record();
break;
case 3:
head=delete_record();
break;
case 4:
head=insert_record();
break;
case 5:
exit(0);
default:
printf("error due to the wrong input !!please input it again!!\n");
}
}while(1);
}
正文
简易的学生管理系统2005-04-29 22:54:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/jay0518/810.html
阅读(4004) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论