当前位置: 代码迷 >> C语言 >> c语言编的学生信息管理系统小程序!!有不足的请指出,谢谢!!
  详细解决方案

c语言编的学生信息管理系统小程序!!有不足的请指出,谢谢!!

热度:188   发布时间:2007-08-05 14:56:37.0
c语言编的学生信息管理系统小程序!!有不足的请指出,谢谢!!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct st
{
char name[20];
int english;
int math;
int chinese;
int average;
st *next;

};
struct st *pend=NULL;//初始链表的尾指针
struct st *pendorder=NULL;//顺序链表的尾指针
struct st *pheadorder=NULL;//顺序链表的头指针
struct st *makeorder(struct st *phead);//按分数从大到小排序 生产链表
struct st *addtolist(struct st *add);// 将平均分最大的添到另一个链表
struct st *createlist();//输入学生信息时生成的初始链表
struct st * deletestu(char *name,st *phead);//删除一个学员的信息
struct st *addstu(st *name,st *phead);//向顺序链表添加一个元素,插入的地方按平均成绩
void printinfo(st *phead);//按平均成绩打印出每个学员的名字

int main()
{
int select;
char deletename[20];
struct st *addstud=NULL;
struct st *phead=NULL;
phead=createlist();//输入时创建链表
pheadorder=makeorder(phead);//将链表排序
printf("input operation:1----deletestudent,2-----addstudent,3----output all student\n");
scanf("%d",&select);
while(select>0)//选择操作1为删除2为添加3为打印,其他的输入会跳出循环
{
switch(select)
{

case 1:
printf("please input the of the student to be deleted:\n");
scanf("%s",deletename);
pheadorder=deletestu(deletename,pheadorder);
printf("input operation:1----deletestudent,2-----addstudent,3----output all student\n");
scanf("%d",&select);
break;
case 2:
printf("please input the information of the student to be added:\n");
addstud=new st;
scanf("%s%d%d%d",addstud->name,&(addstud->english),&(addstud->math),&(addstud->chinese));
addstud->average=((addstud->english)+(addstud->math)+(addstud->chinese))/3;
while((addstud->english)<=0)
{
delete addstud;
printf("please input the information of the student to be added:\n");
addstud=new st;
scanf("%s%d%d%d",addstud->name,&(addstud->english),&(addstud->math),&(addstud->chinese));
addstud->average=((addstud->english)+(addstud->math)+(addstud->chinese))/3;
}
pheadorder=addstu(addstud,pheadorder);
printf("input operation:1----deletestudent,2-----addstudent,3----output all student\n");
scanf("%d",&select);
break;
case 3:
printinfo(pheadorder);
printf("input operation:1----deletestudent,2-----addstudent,3----output all student\n");
scanf("%d",&select);
break;
default:
goto laber;

}
}
laber:system("pause");
return 1;

}
struct st *createlist()//输入时创建初始链表
{
struct st *pfirst=NULL;
struct st *plast=NULL;
struct st *p=new st;
printf("please input the information of the students:\n");
scanf("%s%d%d%d",p->name,&(p->english),&(p->math),&(p->chinese));
p->average=((p->english)+(p->math)+(p->chinese))/3;
while((p->english)>0)
{
if(pfirst==NULL)
pfirst=plast=p;
else
plast->next=p;
plast=p;
printf("please input again:\n");
p=new st;
scanf("%s%d%d%d",p->name,&(p->english),&(p->math),&(p->chinese));
p->average=((p->english)+(p->math)+(p->chinese))/3;

}
plast->next=NULL;
printf("list create successful\n");
delete p;
return pfirst;
}
struct st *deletestu(char *name,st *phead)//删除一个学员
{
int flag=0;
st *p=NULL;
if(strcmp(phead->name,name)==0)
{
phead=phead->next;
flag=1;
}
else
for(p=phead;p;p=p->next)
{
if(strcmp(p->next->name,name)==0)
{
p->next=p->next->next;
flag=1;
break;
}
}
if(!flag)
printf("the student you delete is not in the list\n");
else printf("delete successful\n");
return phead;
}
struct st *addstu(st *name,st *phead)//按平均分增加一个学员
{
name->next=NULL;
struct st *p=NULL;
if((name->average)>(phead->average))
{
name->next=phead;
phead=name;
return phead;
}
else
{
for(p=phead;p->next;p=p->next)
{
if((name->average)>(p->next->average))
{
name->next=p->next;
p->next=name;
return phead;
}


}
}
p=p->next;
p->next=name;
return phead;


}
void printinfo(st *phead)//打印信息
{
st *p;
for(p=phead;p;p=p->next)
printf("%s\n",p->name);
}

struct st *addtolist(struct st *phead,struct st *add)//生成顺序链表时每回都添加一个平均成绩最高的学员信息
{
add->next=NULL;
if(phead==NULL)
pendorder=phead=add;
else
pendorder->next=add;
pendorder=add;
return phead;

}

struct st *makeorder(struct st *phead)//将初始链表变成顺序链表
{
if(phead!=NULL)
{
int max;
struct st *p=NULL;
struct st *index=NULL;
while(phead)
{
max=0;
for(p=phead;p;p=p->next)
{
if(p->average>max)
{
max=p->average;
index=p;
}
}
phead=deletestu(index->name,phead);
pheadorder=addtolist(pheadorder,index);
}
return pheadorder;
}
else printf("there is no list members to be ordered\n");
return pheadorder;
}

搜索更多相关的解决方案: 信息管理系统  c语言  struct  链表  int  

----------------解决方案--------------------------------------------------------
不足啊,超多~~请问你会不会调试,不调试就发上来,找打啊.
----------------解决方案--------------------------------------------------------
晕!!都运行过了!!
----------------解决方案--------------------------------------------------------
就举一例:
struct st * deletestu(char *name,st *phead);//删除一个学员的信息
struct st *addstu(st *name,st *phead);//向顺序链表添加一个元素,插入的地方按平均成绩
void printinfo(st *phead);//按平均成绩打印出每个学员的名字

请问这是什么声明,你自己看看形参.
----------------解决方案--------------------------------------------------------

还有你那个不算得是C,应该是C++,你用了new和delete,而且用//做注释.C里面可没有这些东西.

[此贴子已经被作者于2007-8-5 18:24:01编辑过]


----------------解决方案--------------------------------------------------------
你是说要声明成:
struct st * deletestu(char *name,struct st *phead);
struct st *addstu(struct st *name,struct st *phead);
void printinfo(struct st *phead);
???
----------------解决方案--------------------------------------------------------

请多指教!!


----------------解决方案--------------------------------------------------------
恩!!new和delete是c++里的。我应该用malloc函数。
----------------解决方案--------------------------------------------------------
请楼主找对地方再发吧
----------------解决方案--------------------------------------------------------
都可以运行,还要我调试!!晕!!!
----------------解决方案--------------------------------------------------------