| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3012 人关注过本帖
标题:c语言编的学生信息管理系统小程序!!有不足的请指出,谢谢!!
只看楼主 加入收藏
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
结帖率:100%
收藏
 问题点数:0 回复次数:13 
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 
2007-08-05 14:56
星星鱼虾蟹
Rank: 1
等 级:新手上路
帖 子:191
专家分:0
注 册:2007-6-2
收藏
得分:0 
不足啊,超多~~请问你会不会调试,不调试就发上来,找打啊.

2007-08-05 18:02
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
收藏
得分:0 
晕!!都运行过了!!

要练习算法就来http:///!!有挑战哦!!
2007-08-05 18:09
星星鱼虾蟹
Rank: 1
等 级:新手上路
帖 子:191
专家分:0
注 册:2007-6-2
收藏
得分:0 
就举一例:
struct st * deletestu(char *name,st *phead);//删除一个学员的信息
struct st *addstu(st *name,st *phead);//向顺序链表添加一个元素,插入的地方按平均成绩
void printinfo(st *phead);//按平均成绩打印出每个学员的名字

请问这是什么声明,你自己看看形参.

2007-08-05 18:17
星星鱼虾蟹
Rank: 1
等 级:新手上路
帖 子:191
专家分:0
注 册:2007-6-2
收藏
得分:0 

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

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


2007-08-05 18:20
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
收藏
得分:0 
你是说要声明成:
struct st * deletestu(char *name,struct st *phead);
struct st *addstu(struct st *name,struct st *phead);
void printinfo(struct st *phead);
???

要练习算法就来http:///!!有挑战哦!!
2007-08-05 18:20
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
收藏
得分:0 

请多指教!!


要练习算法就来http:///!!有挑战哦!!
2007-08-05 18:21
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
收藏
得分:0 
恩!!new和delete是c++里的。我应该用malloc函数。

要练习算法就来http:///!!有挑战哦!!
2007-08-05 18:23
jackys2006
Rank: 1
等 级:新手上路
帖 子:195
专家分:0
注 册:2006-3-10
收藏
得分:0 
请楼主找对地方再发吧

2007-08-05 18:34
viky2003
Rank: 5Rank: 5
等 级:职业侠客
帖 子:375
专家分:383
注 册:2007-4-11
收藏
得分:0 
都可以运行,还要我调试!!晕!!!

要练习算法就来http:///!!有挑战哦!!
2007-08-05 19:22
快速回复:c语言编的学生信息管理系统小程序!!有不足的请指出,谢谢!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012483 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved