- 1、本文档共24页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C结构体链表
实验二
学生管理系统
学生数据信息包括:学号、性别、姓名、年龄、联系电话、三门课程成绩(数学、英语、计算机)。设计一个系统,要求:
以链表形式存储信息
有操作界面
实现常用操作:插入、修改、删除、排序输出、查找分数段内学生信息,并统计个数
程序代码:
#includeiostream.h
#includestdio.h
#includestdlib.h
#includestring.h
FILE *f;
struct stu
{
int ID;
char *name;
char *sex;
char *phone;
int age;
struct score
{
float math;
float english;
float computer;
}score;
struct stu *next;
};
struct TempStu
{
int id;
char name[20];
char sex[3];
char phone[13];
int age;
struct score
{
float math;
float english;
float computer;
}score;
};
void open(stu *head,stu *end)
{
struct stu *p=head;
if((f=fopen(studate1,rb))==NULL)
{
cout文件打开失败!;
exit(0);
}
TempStu st;
while(!feof(f))
{
//读出数据并从结构体TemStu中拷贝到stu中
int n = fread(st,sizeof(st),1,f);
if(n1)
break;
p-next=new struct stu;
p-next-name=new char[strlen()+1];
strcpy(p-next-name,);
p-next-sex=new char[strlen(st.sex)+1];
strcpy(p-next-sex,st.sex);
p-next-phone=new char[strlen(st.phone)+1];
strcpy(p-next-phone,st.phone);
p-next-ID=st.id;
p-next-age=st.age;
p-next-score.math=st.score.math;
p-next-score.english=st.score.english;
p-next-puter=puter;
p-next-next=NULL;
p=p-next;
}
fclose(f);
}
struct stu *putin(stu *head,stu *end)
{
//分配新节点并初始化
struct stu *p=new struct stu;
char a[3][30];
cout请输入学号:;
do
{
cinp-ID;
if(!(p-ID)) cout学号不能为零,请重新输入:;
else break;
}while(1);
cout请输入姓名:;
cina[0];
p-name=new char[strlen(a[0])+1];
strcpy(p-name,a[0]);
cout请输入联系电话:;
cina[1];
p-phone=new char[strlen(a[1])+1];
strcpy(p-phone,a[1]);
cout请输入性别:;
cina[2];
p-sex=new char[strlen(a[2])+1];
strcpy(p-sex,a[2]);
cout请输入年龄:;
do
{
cinp-age;
if(p-age18||p-age25) cout年龄范围不能超出18-25,请重新输入:;
else break;
}while(1);
cout请输入数学成绩:;
do
{
cinp-score.math;
if(p-score.math0||p-score.math100)
cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;
else break;
}while(1);
cout请输入英语成绩:;
do
{
cinp-score.english;
if(p-score.english0||p-score.english100)
cout任何一门成绩必须不低于0分,不高于100分,请重新输
文档评论(0)