用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩

[复制链接]
查看11 | 回复1 | 2011-5-18 11:23:01 | 显示全部楼层 |阅读模式
要简单一点的,才学c语言,链表不懂,复杂的可能看不懂,谢谢各位大神了,很急!在线等啊!!!!!!
回复

使用道具 举报

千问 | 2011-5-18 11:23:01 | 显示全部楼层
/*
用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩
*/
//FileName:stuinfo.c

#includestdio.h
#includestdlib.h
#includestring.h
#defineSERIALLEN20
#defineCOURSENUM3

typedefstruct
{
charcourse[SERIALLEN];
floatscore;
}_courseInfo;

typedefstruct_stuinfo
{
charserial[SERIALLEN];
charname[SERIALLEN];
charsex[SERIALLEN];
_courseInfocourseInfo[COURSENUM];
struct_stuinfo*next;
}stuinfo;

intmain(intargc,char**argv)
{
stuinfo*head=NULL,*ptr=NULL,*s=NULL;
charstr[SERIALLEN];
intcycle=1;
inti=0;
memset(str,0,SERIALLEN);
printf(\"建立学生信息:\\n\");
head=(stuinfo*)calloc(1,sizeof(stuinfo));
if(!head)
{
perror(\"申请空间失败,没有足够内存。\");
return-1;
}
ptr=head;
while(cycle)
{
puts(\"输入学生学号(0退出):\");
scanf(\"%s\",str);
if(strcmp(str,\"0\"))//如果学号为0,则退出链表的创建
{
s=(stuinfo*)calloc(1,sizeof(stuinfo));
if(!ptr)
{
perror(\"申请空间失败,没有足够内存。\");
return-1;
}
memset(s-serial,0,SERIALLEN);
strcpy(s-serial,str);
memset(s-name,0,SERIALLEN);
puts(\"输入姓名:\");
scanf(\"%s\",s-name);
memset(s-sex,0,SERIALLEN);
puts(\"输入性别:\");
scanf(\"%s\",s-sex);
for(i=0;iCOURSENUM;i)
{
memset(s-courseInfo.course,0,SERIALLEN);
puts(\"输入课程名称:\");
scanf(\"%s\",s-courseInfo.course);
s-courseInfo.score=0.0f;
puts(\"输入课程分数:\");
scanf(\"%f\",courseInfo.score));
}

ptr-next=s;
ptr=s;
}
elsecycle=0;
}

ptr-next=NULL;
ptr=head;
head=head-next;
free(ptr);
//head=linkSort(head);
ptr=head;
printf(\"学号\\t姓名\\t性别\");
for(i=0;iCOURSENUM;i)
printf(\"\\t课程[%d]\",i);
printf(\"\\n\");
while(ptr!=NULL)
{
printf(\"%s\\t%s\\t%s\",ptr-serial,ptr-name,ptr-sex);
for(i=0;iCOURSENUM;i)
printf(\"\\t%s[%.2f]\",ptr-courseInfo.course,ptr-courseInfo.score);
printf(\"\\n\");
ptr=ptr-next;
}
return0;
}

C:\\myprogcc-g-Wallstudent.c-ostudent

C:\\myprostudent
建立学生信息:
输入学生学号(0退出):
007
输入姓名:
zxsh
输入性别:
male
输入课程名称:
chinese
输入课程分数:
99
输入课程名称:
phy
输入课程分数:
100
输入课程名称:
english
输入课程分数:
98
输入学生学号(0退出):
002
输入姓名:
pipal
输入性别:
female
输入课程名称:
chem
输入课程分数:
98
输入课程名称:
math
输入课程分数:
97
输入课程名称:
chinese
输入课程分数:
100
输入学生学号(0退出):
0
学号姓名性别课程[0]课程[1]课程[2]
007zxshmalechinese[99.00]phy[100.00]english[98.00]
002pipalfemalechem[98.00]math[97.00]chinese[100.00]

C:\\mypro
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行