




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.#include #include #include #include #include #include #include #include #include #define LEN sizeof(struct student) using namespace std; int n=0; /定义一个全局变量统计学生人数 struct student/定义一个学生信息的结构体 char name20; /用来存放姓名的 char sex20; /用来存放性别的 char yuanxi20;/用来存放院系的 long int id; /用来存放学号的 int score4; /用来存放分数的
2、int total; /用来存放总分数的 struct student *next; ; vector stu; class Information public: Information() ; /构造函数. Information() ; /析构函数. student *creat();/建立链表函数。 void output(student *head); int count(student *head);/定义函数count()统计考生总数 student *insert(student*head);/指针函数*insert()用来添加考生信息. student *cancel(stu
3、dent *head,long int num);/指针函数*cancel()用来删除考生信息. student *find(student *head,long int num); /指针函数*find()用来查找考生信息. void inorder(student *head);/定义inorder()函数将考生的总分从大到小排列并输出 void average( student *head);/求学生成绩的平均分的函数 void save(student *head);/保存函数 student *Read();/读取函数 private: student *p1,*p2,*p3,*he
4、ad,st; ; Information:Information() /构造函数 cout *n; cout -n; cout *nn; Information:Information() /构造函数 cout *n; cout -n; cout *n; student *Information:creat(void) /定义一个指向struct student的结构体指针函数*creat()用来增加学生信息. char ch20;n=0; /用来存放姓名的 p1=p2=(student *)malloc(LEN);/调用malloc()函数用来开辟一个新的存储单元 cout -endl; c
5、outch; head=NULL; /给指针head赋初值 while (strcmp(ch,!)!=0) /调用字符比较函数strcmp()用来判断是否继续输入 char str10; int flag=0; p1=(student *)malloc(LEN);/调用malloc()函数用来开辟一个新的存储单元 strcpy(p1-name,ch); /将循环结构前面输入的姓名复制到结构体名为p1的数组name中 coutp1-sex; coutstr; coutstr; if(atol(str)999999999 | atol(str)1) coutid=atol(str); flag=1
6、; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore0=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore1=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore2=atoi(str); flag=1; while(flag=0); flag=0;
7、 coutstr; if(atoi(str)100 | atoi(str)1) coutscore3=atoi(str); flag=1; while(flag=0); flag=0; p1-total=p1-score0+p1-score1+p1-score2+p1-score3;/计算总分 if(n=0)head=p1;/如果是输入第一组学生考试信息就将指针p1赋给指针head else p2-next=p1;/否则将p1赋给p2所指结构体的next指针 p2=p1;/将指针p1赋给指针p2 n+; /将n的值加1 coutch;/将输入的姓名存放到字符数组ch中 p2-next=NULL
8、;/将p2所指结构体的next指针重新赋空值 return (head);/将输入的第一组学生考试信息返回 void Information:output(student *head) /定义output()函数将学生的信息从头指针所指内容开始输出 if(head=NULL) cout 这是一个空表,请先输入考生成绩.n; else cout-n; cout *学生成绩信息表*n; cout-n; cout学号 姓 名 性别 院系 语文 英语 数学 C+ 平均成绩 总分n; cout-n; p1=head;/将头指针赋给p do coutsetw(8)id setw(9)name setw(8
9、)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; coutnext;/将下一组学生信息的next指针赋给p while(p1!=NULL);/若指针p非空则继续,目的是把所有的学生信息都传给指针p然后输出. /统计学生人数的函数 int Information:count(struct student *head)/定义函数count()统计考生总数 if(head=NULL) /若指针head为空返回值为0 return(0); else re
10、turn(1+count(head-next);/函数的递归调用 /插入学生的成绩信息的函数 student *Information:insert( student *head) /插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加考生信息. char str10; int flag=0; coutt-nendl; p1=(student *)malloc(LEN); /使p1指向插入的新结点 coutp1-name; /将输入的姓名存放到结构体名为p1的数组name中 coutp1-sex; coutstr; if(atol(str)9999999
11、9 | atol(str)1) coutid=atol(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore0=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore1=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore2=a
12、toi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore3=atoi(str); flag=1; while(flag=0); flag=0; p1-total=p1-score0+p1-score1+p1-score2+p1-score3;/计算总分 p2=head;/将头指针赋给p2 if(head=NULL) /若没调用次函数以前的头指针head为空 head=p1;p1-next=NULL;/则将p1赋给头指针head并将p1所指结构体成员指针next赋空值 els
13、e while(p1-idp2-id)&(p2-next!=NULL) p3=p2;/p3指向原p2指向的结点 p2=p2-next; /p2后移一个结点 if(p1-idid) if(head=p2) p1-next=head; head=p1; /插入到第一个结点之前 else p3-next=p1; p1-next=p2; /插入到p3所指结点之后 else p2-next=p1; p1-next=NULL; /插入到尾结点之后 n+;/将学生人数加1 coutt你输入的学生信息已经成功插入id&p1-next!=NULL)/寻找要删除的结点当p1所指的学号不是输入的学号并且p1所指的n
14、ext指针不为空 p2=p1; p1=p1-next; /p2指向原p1指向的结点p1后移一个结点 if(num=p1-id)/如果输入的学生准考证号是p1所指的学号结点找到后删除 if(p1=head) head=p1-next;/如果head指针和p1指针相等则将下一个结点赋给指针head else p2-next=p1-next;/否则将p1所指结点赋给p2所指结点将要删除的学生信息跳过去 cout 删除学号为num的学生n; n-;/将学生人数减1 return(head);/将头指针返回 /查找学生信息函数 student *Information:find(student *hea
15、d,long int num) /定义一个指向struct student的结构体指针函数*find()用来查找学生信息. if(head=NULL)/若调用次函数以前的头指针head为空 coutid&p1-next!=NULL) /寻找结点当p1所指的学号不是输入的学生学号并且p1所指的next指针不为空 p1=p1-next; /p1后移一个结点 if(num=p1-id)/如果要查找的学号是p1所指的学号 cout-n; cout学号 姓名 性别 院系 语文 英语 数学 C+ 平均分 总分 n; cout-n; coutsetw(8)id setw(9)name setw(8)sex
16、setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; cout-n; else cout 没找到学号为num的学生.n; /结点没找到 return(head); void Information:inorder(student *head) /定义inorder()函数将考生的总分从大到小排列并输出 int i,k,m=0,j; student *p20;/定义一个指向struct student的结构体指针数组p if(head!=NULL)/如果头指针是
17、空则继续 m=count(head); cout-n; cout学生成绩统计表n; cout-n; cout学号 姓 名 性别 院系 语文 英语 数学 C+ 平均分 总分 名次n; cout-n; p1=head; for(k=0;knext; for(k=0;km-1;k+) /选择排序法 for(j=k+1;jtotaltotal) p2=pk; pk=pj; pj=p2; for(i=0;im;i+) coutsetw(8)id setw(9)name setw(8)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score
18、3 setw(6)total/4.0 setw(11)totalendl; cout-n; void Information:average(student *head) /求各科平均成绩的函数 int k,m; float arg1=0,arg2=0,arg3=0,arg4=0; if(head=NULL)/如果头指针是空则继续 cout 这是一个空表,请先输入学生成绩.n; else m=count(head); p1=head; for(k=0;kscore0; arg2+=p1-score1; arg3+=p1-score2; arg4+=p1-score3; p1=p1-next;
19、arg1/=m;arg2/=m;arg3/=m;arg4/=m; cout全班单科成绩平均分n; cout-n; cout 语文平均分:setw(7)arg1 英语平均分:setw(7)arg2 数学平均分:setw(7)arg3 C+平均分:setw(7)arg4endl; cout-n; void Information:save(student *head) /保存函数. ofstream out(data.txt,ios:out); outcount(head)endl; while(head!=NULL) outnamet idtt sext score0t score1t scor
20、e2t score3t totalnext; student *Information:Read() /读取函数的实现 int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in(data.txt,ios:out); ini; if(i=0)cout data.txt 文件中的数据为空,请先输入数据。endl; return 0; else cout 0;i-) p1=(student *)malloc(LEN); st.idst.sex st.score0st.score1st.score2st.score
21、3 st.total; strcpy(p1-name,); p1-id=st.id; strcpy(p1-sex,st.sex); p1-score0=st.score0; p1-score1=st.score1; p1-score2=st.score2; p1-score3=st.score3; p1-total=st.total; if(n=0)head=p1;/如果是输入第一组学生考试信息就将指针p1赋给指针head else p2-next=p1;/否则将p1赋给p2所指结构体的next指针 p2=p1;/将指针p1赋给指针p2 n+; /将n的值加1 cout name
22、t /显示读入数据 idtt sext score0t score1t score2t score3t totalendl; cout endl; / cout 数据已经成功读取完毕。next=NULL; return (head); int main() /主函数. system(color 4f);/改变登陆界面颜色 Information person; student *head=NULL; char str5; int flag=0; int choice; long int i; char admin20; char pass30; coutadmin; coutpass; if(strcmp(admin,1111)=0&strcmp(pass,222)=0) do cout *endl; cout 学生信息管理系统主菜单界面 *endl ; cout endl; coutendl; cout .输入学生信息 endl; cout .显示学生信息 endl; cout .排序统计成绩 endl; cout .查找学生信息 endl; cout .增加学生信息 endl; cout .删除学生信息 endl; cout .保存退出系统 endl; coutendl; coutstr; if(atoi(str)7 | atoi(str)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中药调剂员实操任务书
- 1,4-丁二醇装置操作工职业技能模拟试卷含答案
- 产品缝制工安全教育培训手册
- 普通镗床理论学习手册练习试题及答案
- 数控铣床职业技能模拟试卷含答案
- 邮件分拣员基础技能培训手册
- 环境监测及废物处理人员岗位实习报告
- 货运检查员应急处置分析及对策
- 环境监测及废物处理人员安全教育培训手册
- 畜牧技术员应急处置分析及对策
- 《电子沙盘》课件
- DB32T 1590-2010 钢管塑料大棚(单体)通 用技术要求
- 阿片类药物不良反应综合防治专家共识(2024年版)
- 2024版无人机研发与定制合同
- 精神病缄默状态
- 企业员工手机管理制度与规范
- 2025年中考物理一轮复习资料配套练习专题02 光现象(测试)(含答案)
- 蒋诗萌小品《谁杀死了周日》台词完整版
- 《经济法学》(第三版)电子教案
- 婚礼流程及费用清单
- DB4116-T 059-2024 智慧消防运维服务规范
评论
0/150
提交评论