版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、vc学生信息管理系统悬赏分:0 - 解决时间:2008-6-11 16:46 1)能够从屏幕上读取一个学生的信息并将信息存入到数据文件中。2)能够将指定的信息从文件中删除。3)能够按编号、姓名对学生的信息进行检索并将检索结果显示在屏幕上。4)可以统计全部学生的总成绩,及其在班上的排名。5)能够统计各科的平均成绩及及格率。6)要求有错误提示功能,例如性别只能输入男女,输入错误提示重新输入。7)如果检索不到相应的信息应提示用户。 #include #include #include #include #include #include #include #include #include /#de
2、fine NULL 0 int const Q=20; #define LEN sizeof(struct student) using namespace std; int n=0; /定义一个全局变量统计学生人数 /-定义一个学生考试信息的结构体 struct student char nameQ; /用来存放姓名的 char sexQ; /用来存放性别的 long int id; /用来存放准考证号的 int score4; /用来存放分数的 int total; /用来存放总分数的 struct student *next; ; /student向量容器 vector stu; /-学
3、生类 class Information public: Information() ; /构造函数. Information() ; /析构函数. student *creat();/建立链表函数。 void output(student *head); int count(student *head);/定义函数count()统计考生总数 student *insert(student*head);/指针函数*insert()用来添加考生信息. student *cancel(student *head,long int num);/指针函数*cancel()用来删除考生信息. stude
4、nt *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,*head,st; ; Information:Information() cout *n; cout -n; c
5、out *nn; Information:Information() cout *n; cout -n; cout *n; student *Information:creat(void) /定义一个指向struct student的结构体指针函数*creat()用来增加考生信息. char chQ;n=0; /用来存放姓名的 p1=p2=(student *)malloc(LEN);/调用malloc()函数用来开辟一个新的存储单元 cout -endl; coutch; head=NULL; /给指针head赋初值 while (strcmp(ch,!)!=0) /调用字符比较函数strc
6、mp()用来判断是否继续输入 char str10; int flag=0; p1=(student *)malloc(LEN);/调用malloc()函数用来开辟一个新的存储单元 strcpy(p1-name,ch); /将循环结构前面输入的姓名复制到结构体名为p1的数组name中 coutp1-sex; coutstr; if(atol(str) | atol(str)1) coutid=atol(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore0=atoi(str);
7、 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; coutstr; if(atoi(str)100 | atoi(str)1) coutscore3=atoi(str); flag=1; while(flag=0);
8、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;/将p2所指结构体的next指针重新赋空值 return (head);/将输入的第一组学生考试信息返回 /-定义output()函数将考生的信息从头指针所指内容开始输
9、出 void Information:output(student *head) 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)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/
10、4.0 setw(11)totalendl; coutnext;/将下一组考生信息的next指针赋给p while(p1!=NULL);/若指针p非空则继续,目的是把所有的考生信息都传给指针p然后输出. /-统计学生人数的函数 int Information:count(struct student *head)/定义函数count()统计考生总数 if(head=NULL) return(0);/若指针head为空返回值为0 else return(1+count(head-next);/函数的递归调用 /-插入学生的成绩的函数 student *Information:insert( st
11、udent *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) | atol(str)1) coutid=atol(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)
12、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; coutstr; if(atoi(str)100 | atoi(str)1) coutsc
13、ore3=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赋空值 else while(p1-idp2-id)&(p2-next!=NULL) p3=p2;/p3指向原p2指向的结点 p2=p2-next; /p2后移一个结点 if(p1-i
14、did) 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你输入的学生信息已经成功插入删除函数 student *Information:cancel(student *head,long int num)/定义一个指向struct student的结构体指针函数*delete()用来删除考生信息. if(head=NULL)/若调用次函数以前的头指针
15、head为空 return(head); else p1=head;/否则将头指针赋给p1 while(num!=p1-id&p1-next!=NULL)/寻找要删除的结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空 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所指结
16、点赋给p2所指结点将要删除的学生信息跳过去 cout 删除准考证号为num查找函数 student *Information:find(student *head,long int num) /定义一个指向struct student的结构体指针函数*find()用来查找考生信息. if(head=NULL)/若调用次函数以前的头指针head为空 coutid&p1-next!=NULL) /寻找结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空 p1=p1-next; /p2指向原p1指向的结点p1后移一个结点 if(num=p1-id)/如果要查找的学生准考
17、证号是p1所指的学生准考证号 cout-n; cout准考证号 姓名 性别 计算机组成原理 概率统计 英语 C+ 平均分 总分 n; cout-n; coutsetw(8)id setw(9)name setw(8)sex 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); /-定义inorder()函数将考生的总分从大到小排列并输出 void
18、Information:inorder(student *head) int i,k,m=0,j; student *pQ;/定义一个指向struct student的结构体指针数组p if(head!=NULL)/如果头指针是空则继续 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; p
19、k=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)score3 setw(6)total/4.0 setw(11)totalendl; cout求各科平均分成绩的函数 void Information:average(student *head) int k,m; float arg1=0,arg2=0,arg3=0,arg4=0; if(head=NULL)/如果头指针是空则继续 cout
20、 这是一个空表,请先输入考生成绩.n; else m=count(head); p1=head; for(k=0;kscore0; arg2+=p1-score1; arg3+=p1-score2; arg4+=p1-score3; p1=p1-next; 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保存函数. void Informatio
21、n:save(student *head) ofstream out(data.txt,ios:out); outcount(head)endl; while(head!=NULL) outnamet idtt sext score0t score1t score2t 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 文
22、件中的数据为空,请先输入数据。endl; return 0; else cout 0;i-) p1=(student *)malloc(LEN); st.idst.sex st.score0st.score1st.score2st.score3 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.
23、total; if(n=0)head=p1;/如果是输入第一组学生考试信息就将指针p1赋给指针head else p2-next=p1;/否则将p1赋给p2所指结构体的next指针 p2=p1;/将指针p1赋给指针p2 n+; /将n的值加1 /显示读入数据 cout namet idtt sext score0t score1t score2t score3t totalendl; cout endl; / cout 数据已经成功读取完毕。next=NULL; return (head); /-主函数. int main(void) Information person; student *
24、head=NULL; char str10; int flag=0; int choice; long int i; head=person.Read(); do coutendl; cout 学生成绩管理系统主菜单界面 endl ; cout 读取数据请输入数字零 endl; coutendl; cout .输入学生成绩 endl; cout .显示学生成绩 endl; cout .排序统计成绩 endl; cout .查找学生成绩 endl; cout .增加学生成绩 endl; cout .删除学生成绩 endl; cout .保存退出系统 endl; coutendl; coutstr
25、; if(atoi(str)7 | atoi(str)1) cout对不起,请输入1-7这几个数字!n; else choice=atoi(str); switch(choice) case 1: head=person.creat(); break; case 2: person.output(head); break; case 3: person.inorder(head); person.average(head); cout 参加考试的学生人数为:person.count(head)人n; break; case 4: coutstr; if(atol(str) | atol(str
26、)1) cout对不起,请输入正确输入!n; else i=atol(str); flag=1; while(flag=0); flag=0; person.find(head,i); break; case 5: head=person.insert(head); person.output(head); break; case 6: coutstr; if(atol(str) | atol(str)1) cout对不起,请输入正确输入!hn; else i=atol(str); flag=1; while(flag=0); flag=0; head=person.cancel(head,i
27、); person.output(head); break; case 7: person.save(head); cout文件已保存!可以安全退出!endl; break; default :cout 相关内容 求毕业论文 VC“学生信息管理系统”2010-5-25 用VC+做“学生信息管理系统”的登录界面32008-3-19 谁能帮我vc+做个学生信息管理系统52008-5-29 用VC编写一个学生信息管理系统2008-7-5 谁能提供一下用VC+制作一个学生信息管理系统的代码的啊?12010-7-4更多关于vc 学生管理系统的问题查看同主题问题: 学生信息管理系统 等待您来回答更多 0回
28、答 谁有易学C+这本书的电子版帮忙发带 0回答 20 Linux windows socket 传输问题 0回答 C+简单问题,谢谢。 0回答 苹果电脑YY语音的声卡驱动在哪里? QQ 0回答 荣成方正房地产公司开发的宝月山庄怎么样 0回答 c语言中(a)(b) ? (a):(b)什么意思 0回答 急!在线等! 0回答 屡败屡战说明了什么道理 其他回答共 1 条#include #include #include struct stud long num; char name20; double score; ; typedef struct stucode struct stud
29、 student ; struct stucode *next; L; void menu(); void createlist(struct stucode *r); void out(struct stucode *r); void search1(struct stucode *r); void search2(struct stucode *r); void del(struct stucode *r); void insert(struct stucode *r); void sort(struct stucode *r); void main() char choose; int
30、flag=1; struct stucode *r=NULL; while(flag) system(cls); menu(); choose=getchar(); switch(choose) case 1: createlist(&r); out(r); printf(Testing function 1nPress any key to continuen); getchar(); getchar(); break; case 2: search1(r); printf(Testing function 1nPress any key to continuen); getchar();
31、getchar(); break; case 3: search2(r); printf(Testing function 1nPress any key to continuen); getchar(); getchar(); break; case 4: del(&r); out(r); printf(Testing function 1nPress any key to continuen); getchar(); getchar(); break; case 5: insert(&r); out(r); printf(Testing function 1nPress any key t
32、o continuen); getchar(); getchar(); break; case 6: sort(&r); out(r); printf(Testing function 1nPress any key to continuen); getchar(); getchar(); break; case 7: out(r); printf(Testing function 7nPress any key to continuen); getchar(); getchar(); break; case 0: flag=0; printf(The end.n); break; defau
33、lt: printf(nWrong Selection!(选择错误,请重选!)n);getchar();getchar(); void createlist(struct stucode *r) struct stucode *p,*t; long n; char a20; double s; if(*r) *r=NULL; printf( n请输入:n 学号(请按学号升序排列) 姓名 分数 (若要结束请输入三个为零)n); scanf(%ld%s%lf,&n,a,&s); if(n=0) return; p=(L *)malloc(sizeof(L); p-student.num=n; st
34、rcpy(,a); p-student.score=s; p-next=NULL; *r=p; scanf(%ld%s%lf,&n,a,&s); while(n) t=p; p=(L *)malloc(sizeof(L); p-student.num=n; strcpy(,a); p-student.score=s; p-next=NULL; t-next=p; scanf(%ld%s%lf,&n,a,&s); void search1(struct stucode *r) long x; if(!r) printf(没有学生信息可查询!
35、n); return ; printf( 请输入要查询的学生信息的学生学号:n); scanf(%ld,&x); while(r&r-student.num!=x) r=r-next; if(r=NULL) printf(Error! No such student !n); else printf(%ld %s %.2lfn,r-student.num,,r-student.score); void search2(struct stucode *r) char m20; if(!r) printf(没有学生信息可查询!n); return ; printf( 请
36、输入要查询的学生信息的学生姓名:n); scanf(%s,m); while(r&strcmp(,m) r=r-next; if(r=NULL) printf(Error! No such student !n); else printf(%ld %s %.2lfn,r-student.num,,r-student.score); void del(struct stucode *r) long k; struct stucode *p=*r,*t; if(!(*r) printf(没有学生信息可删除 !n); return ; printf( 请输入要删除的学生信息的学生学号:n); scanf(%ld,&k); if(p-student.num=k) *r=(*r)-next,free(p); else while(p-next&p-next-student.num!=k) p=p-next; if(p-next=NULL) printf(Error! No
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- KSA01-生命科学试剂-MCE
- 2026年趣味音乐测试题及答案
- 2026年流星追逐记测试题及答案
- 2026年委托推理测试题及答案
- 个人整改报告2026(2篇)
- 2026年草业科学类测试题及答案
- 2026年新闻行业测试题及答案
- 2026年保险课程研发测试题及答案
- (2026年)公司员工工伤管理制度
- 医院母婴同室医院感染管理制度2篇
- 北师大版八年级数学上册勾股定理《探索勾股定理》示范教学课件
- JJG 521-2024环境监测用X、γ辐射空气比释动能率仪检定规程
- 新中国成立75周年农业发展成就课件(含讲稿)
- 音乐心理治疗相关行业项目操作方案
- 2024北京高考政治+历史+地理试卷(真题+答案)
- LNG汽车车载钢瓶充装作业指导书
- DL-T5706-2014火力发电工程施工组织设计导则
- 知识产权信息检索与利用 知到智慧树网课答案
- 《也是冬天-也是春天》
- 劳动人事争议仲裁员培训考试试题及答案以及劳动合同法复习重点
- S7-1200 PLC 应用技术 课件全套 项目1-5 S7-1200 PLC控制三相异步电动机 - S7-1200 PLC控制步进电机与伺服电机
评论
0/150
提交评论