p3=p3->nexgt是什么意思思

学生成绩管理系统 发布时间:
2008-09-03 01:25:42
303770957
发布留言 2005-9-10 01:37
学生成绩管理系统
要求:有10个学生、4门课程,可以求全班单科的平均分,某个人的多门课的平均分、有输入,显示,修改、删除、排序,查询数据等功能。
界面要求:全屏设计,提示信息准确汉化,所有功能可以反复使用,用菜单管理。
数据类型至少要用到结构体和数组,使用文件进行存储和管理。
#include " tdlib.h
#include " tring.h
#include " tdio.h
#define NULL 0
#define Q 10
#define LEN sizeof(struct student)
struct student /*定义一个学生考试信息的结构体*/
{char name[Q] /*用来存放姓名的*/ char sex[Q] /*用来存放性别的*/ long id /*用来存放准考证号的*/ int score[4] /*用来存放分数的*/ int total /*用来存放总分数的*/ int m_c /*用来存放名次的*/ truct student *next;/*定义指向下一个结构体的指针*/ #125 int /*用来统计考生人数的*/
char ch[Q] /*用来存放姓名的*/
struct student *creat() /*定义一个指向struct student的结构体指针函数*creat()用来修改考生信息.*/
{int i;
struct student *head,*p1,*p2;/*定义三个指向struct student的结构体指针*/
p1=p2=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/
printf(请输入学生考试信息!\ quot;);
printf(请在姓名处键以\!\结束输入。\ quot;);
printf(姓名:);
scanf(% quot;,ch);
head=NULL; /*给指针head赋初值*/
while (strcmp(ch,!)!=0) /*调用字符比较函数strcmp()用来判断是否继续输入*/ #123 1=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/ trcpy(p1-&am gt ame,ch); /*将循环结构前面输入的姓名复制到结构体名为p1的数组name中*/ rintf(性别:); canf(% quot;,p1-&am gt ex); rintf(准考证号(8位):); canf(%ld,&am am 1-id);/*将输入的准考证号存放到p1所指结构体的数组id中*/ rintf(数学成绩:); canf(%d,&am am 1-&am gt core[0]);/*将输入的数学成绩存放到p1所指结构体的数组score中*/ rintf(物理成绩:); canf(%d,&am am 1-&am gt core[1]);/*将输入的物理成绩存放到p1所指结构体的数组score中*/ rintf(英语成绩:); canf(%d,&am am 1-&am gt core[2]);/*将输入的英语成绩存放到p1所指结构体的数组score中*/ rintf(C语言成绩:); canf(%d,&am am 1-&am gt core[3]);/*将输入的C语言成绩存放到p1所指结构体的数组score中*/ 1-total=p1-&am gt core[0]+p1-&am gt core[1]+p1-&am gt core[2]+p1-&am gt core[3];/*计算总分 */ if(n==0)head=p1;/*如果是输入第一组学生考试信息就将指针p1赋给指针head*/ else p2-&am gt ext=p1;/*否则将p1赋给p2所指结构体的next指针*/ 2=p1;/*将指针p1赋给指针p2*/ ++ /*将n的值加1*/ rintf(姓名:); canf(% quot;,ch);/*将输入的姓名存放到字符数组ch中*/ #125; 2-&am gt ext=NULL;/*将p2所指结构体的next指针重新赋空值*/ return (head);/*将输入的第一组学生考试信息返回*/
void output(struct student *head) /*定义output()函数将考生的信息从头指针所指内容开始输出*/ #123 truct student * /*定义一个指向struct student的结构体指针p*/ rintf(-----------------------------------------------------------------------\ quot;); rintf(" *学生考试成绩信息表*\ quot;); rintf(-----------------------------------------------------------------------\ quot;); /*71个“-”*/ rintf(准考证号 姓 名 性别 数学 物理 英语 C语言 平均分 总分\ quot;); rintf(-----------------------------------------------------------------------\ quot;); =head;/*将头指针赋给p*/ if(head!=NULL)/*如果头指针非空则继续*/ do{ rintf(%8ld %6 %4 %2d %2d %2d %2d %-.2f %3d\ quot;,p-id,p-&am gt ame,p-&am gt ex,p-&am gt core[0],p-&am gt core[1],p-&am gt core[2],p-&am gt core[3],p-total/4.0,p-total); rintf(-----------------------------------------------------------------------\ quot;); =p-/*将下一组考生信息的next指针赋给p*/ #125;while(p!=NULL);/*若指针p非空则继续,目的是把所有的考生信息都传给指针p然后输出.*/ #125;
count(struct student *head)/*定义函数count()统计考生总数*/ {if(head==NULL)return(0);/*若指针head为空返回值为0*/ else return(1+count(head-&am gt ext));/*函数的递归调用*/ #125;
struct student *i ert(struct student*head) /*插入新结点定义一个指向struct student的结构体指针函数*i ert()用来添加考生信息.*/ #123 truct student *p1,*p2,*p3;/*定义三个指向struct student的结构体指针*/ printf(请输入修改信息!\ quot;); p1=(struct student *)malloc(LEN) /*使p1指向插入的新结点*/ printf(准考证号(8位):); scanf(%ld,&am am 1-id); /*将输入的准考证号存放到p1所指结构体的数组id中*/ printf(姓名:); scanf(% quot;,p1-&am gt ame); /*将输入的姓名存放到结构体名为p1的数组name中*/ printf(性别:); scanf(% quot;,p1-&am gt ex); printf(数学成绩:); scanf(%d,&am am 1-&am gt core[0]);/*将输入的数学成绩存放到p1所指结构体的数组score中*/ printf(物理成绩:); scanf(%d,&am am 1-&am gt core[1]);/*将输入的物理成绩存放到p1所指结构体的数组score中*/ printf(英语成绩:); scanf(%d,&am am 1-&am gt core[2]);/*将输入的英语成绩存放到p1所指结构体的数组score中*/ printf(C语言成绩:); scanf(%d,&am am 1-&am gt core[3]);/*将输入的C语言成绩存放到p1所指结构体的数组score中*/ p1-total=p1-&am gt core[0]+p1-&am gt core[1]+p1-&am gt core[2]+p1-&am gt core[3];/*计算总分 */ p2=head;/*将头指针赋给p2*/ if(head==NULL) /*若没调用次函数以前的头指针head为空*/ {head=p1 1-&am gt ext=NULL #125;/*则将p1赋给头指针head并将p1所指结构体成员指针next赋空值*/ else {while((p1-id&am gt 2-id)&am am am am (p2-&am gt ext!=NULL)) { 3=p2;/*p3指向原p2指向的结点*/ 2=p2-&am gt ext #125;/*p2后移一个结点*/ if(p1-id=p2-id) {if(head==p2){ 1-&am gt ext=head;head=p1 #125 /*插入到第一个结点之前*/ else { 3-&am gt ext=p1 1-&am gt ext=p2 #125 /*插入到p3所指结点之后*/ #125; else{ 2-&am gt ext=p1 1-&am gt ext=NULL #125 /*插入到尾结点之后*/ } ++;/*将学生人数加1*/ return(head); #125;
struct student *delete (struct student *head,long int num)/*定义一个指向struct student的结构体指针函数*delete()用来删除考生信息.*/ { truct student *p1,*p2; /*定义两个指向struct student的结构体指针*/ rintf(要删除的学生准考证号为:%ld\ quot;,num); if(head==NULL)/*若调用次函数以前的头指针head为空*/ #123 rintf(这是一个空表,没有可删除的学生准考证号!\ quot;);return(head) #125; else{ 1=head;/*否则将头指针赋给p1*/ while(num!=p1-id&am am am am 1-&am gt ext!=NULL)/*寻找要删除的结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空*/ #123 2=p1 1=p1-&am gt ext #125;/*p2指向原p1指向的结点p1后移一个结点*/ if(num==p1-id)/*如果输入的学生准考证号是p1所指的学生准考证号*//*结点找到后删除*/ #123;if(p1==head) head=p1-/*如果head指针和p1指针相等则将下一个结点赋给指针head*/ else p2-&am gt ext=p1-/*否则将p1所指结点赋给p2所指结点将要删除的学生信息跳过去*/ printf(删除准考证号为%ld的学生\ quot;,num); n-- #125;/*将学生人数减1*/ else printf(没找到准考证号为%ld的学生!\ quot;,num) /*结点没找到*/ return(head);/*将头指针返回*/ } #125;
struct student *find(struct student *head,long int num) /*定义一个指向struct student的结构体指针函数*find()用来查找考生信息.*/ #123 truct student *p1; /*定义一个指向struct student的结构体指针*/ rintf(要查找的学生准考证号为:%ld\ quot;,num); if(head==NULL)/*若调用次函数以前的头指针head为空*/ #123 rintf(这是一个空表,没有要查找的学生准考证号!\ quot;);return(head) #125; else{ 1=head;/*否则将头指针赋给p1*/ while(num!=p1-id&am am am am 1-&am gt ext!=NULL)/*寻找结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空*/ { 1=p1-&am gt ext #125;/*p2指向原p1指向的结点p1后移一个结点*/ if(num==p1-id)/*如果要查找的学生准考证号是p1所指的学生准考证号*/ #123; printf(------------------------------------------------------------------------------\ quot;);/*71个“-”*/ rintf(准考证号 姓 名 性别 数学 物理 英语 C语言 平均分 总分 名次\ quot;); rintf(------------------------------------------------------------------------------\ quot;);/*71个“-”*/ rintf(%8ld %6 %4 %2d %2d %2d %2d %-.2f %3d %-2d\ quot;,p1-id,p1-&am gt ame,p1-&am gt ex,p1-&am gt core[0],p1-&am gt core[1],p1-&am gt core[2],p1-&am gt core[3],p1-total/4.0,p1-total,p1-m_c); rintf(------------------------------------------------------------------------------\ quot;); } else printf(没找到准考证号为%ld的学生!\ quot;,num) /*结点没找到*/ return(head); } #125;
paixu(struct student *head) /*定义paixu()函数将考生的总分从大到小排列并输出*/ #123;int i,k,m,j; truct student *p1,*p2,*p[Q];/*定义一个指向struct student的结构体指针数组p*/ m=count(head); if(head==NULL)/*如果头指针是空则继续*/ #123 rintf(这是一个空表,请先输入考生成绩!\ quot;) #125; else { rintf(------------------------------------------------------------------------------\ quot;);/*78个“-”*/ rintf(" *学生考试成绩统计表*\ quot;); rintf(------------------------------------------------------------------------------\ quot;);/*78个“-”*/ rintf(准考证号 姓 名 性别 数学 物理 英语 C语言 平均分 总分 名次\ quot;); rintf(------------------------------------------------------------------------------\ quot;);/*78个“-”*/ 1=head; for(k=0;km;k++) { [k]=p1 1=p1-&am gt ext #125; for(k=0;km-1;k++) /*选择排序法*/ for(j=k+1;jm;j++) if(p[k]-total&am lt [j]-total) #123 2=p[k] [k]=p[j] [j]=p2 #125 /*从大到小排列的指针*/ #125; for(i=0;im;i++) #123 rintf(%8ld %6 %4 %2d %2d %2d %2d %-.2f %3d %-2d\ quot;,p-&am gt ame,p-&am gt core[0],p,p,p,p-total,i+1); rintf(------------------------------------------------------------------------------\ quot;);/*78个“-”*/ arg2+=p1-&am gt core[1]; arg3+=p1-&am gt core[2]; arg4+=p1-&am gt core[3]; 1=p1-&am gt ext #125; arg1/=m;arg2/=m;arg3/=m;arg4/=m; rintf(" *全班单科成绩平均分*\ quot;); rintf(------------------------------------------------------------------------------\ quot;);/*71个“-”*/ rintf(数学平均分:%.2f 物理平均分:%.2f 英语平均分:%.2f C语言平均分:%.2f \ quot;,arg1,arg2,arg3,arg4); rintf(------------------------------------------------------------------------------\ quot;);/*71个“-”*/ #125;
void main() #123;int k; truct student *head; long i; rintf(************************\ quot;); rintf(|学生成绩系统主菜单界面|\ quot;); rintf(| 1.输入学生成绩 |\ quot;); rintf(| 2.显示学生成绩 |\ quot;); rintf(| 3.修改学生成绩 |\ quot;); rintf(| 4.删除学生成绩 |\ quot;); rintf(| 5.排序学生成绩 |\ quot;); rintf(| 6.查找学生成绩 |\ quot;); rintf(| 7.安全退出系统 |\ quot;); rintf(| -学生成绩管理
- |\ quot;); rintf(************************\ quot;); head=creat(); do{ rintf(************************\ quot;); rintf(|学生成绩系统主菜单界面|\ quot;); rintf(| 1.输入学生成绩 |\ quot;); rintf(| 2.显示学生成绩 |\ quot;); rintf(| 3.修改学生成绩 |\ quot;); rintf(| 4.删除学生成绩 |\ quot;); rintf(| 5.排序学生成绩 |\ quot;); rintf(| 6.查找学生成绩 |\ quot;); rintf(| 7.安全退出系统 |\ quot;); rintf(| -学生成绩管理
- |\ quot;); rintf(************************\ quot;); rintf(请输入选择号(1--7):); canf(%d,&am am k); witch(k) { case 1:head=creat() reak; case 2:output(head) rintf(参加考试的学生人数为:%d人\ quot;,count(head)) rintf(请按任意键显示主菜单!\ quot;);getch() reak; case 3:head=i ert(head);output(head) rintf(请按任意键显示主菜单!\ quot;);getch(); break; case 4:printf(请输入要删除的准考证号(8位):) canf(%ld,&am am i);head=delete(head,i);output(head) rintf(请按任意键显示主菜单!\ quot;);getch(); break; case 5:paixu(head);dkarg(head) rintf(参加考试的学生人数为:%d人\ quot;,count(head)) rintf(请按任意键显示主菜单!\ quot;);getch() reak; case 6:printf(请输入要查找的准考证号(8位):) canf(%ld,&am am i);head=find(head,i) rintf(请按任意键显示主菜单!\ quot;);getch() reak; default:break; #125; #125;while(k!=7); #125;
但是要求用文件存储输入信息,请各为高手帮帮忙!谢谢!急用!
发布留言 2006-2-26 15:44
tianykun
发布留言 2006-3-2 09:21
*** 作者被禁止或删除 内容自动屏蔽 ***
发布留言 2006-3-5 20:20
没看 你是要问文件的读写是吧~
要含有头文件fstream
如果要从abc.txt中读取
ifstream fin(abc.txt);
要存入xyz.txt文件中
ofstream fout(xyz.txt);
如果不加参数就是默认模式。。。。就是文件中原有的数据会被替换
fi fout就和ci cout用法一样拉`
发布留言 2006-3-6 19:40
[em17][em17][em17]
热情依然
发布留言 2006-3-7 11:02
四楼说出的是C++语法来的,如果用C就是用fopen打开文件,用fclose()关闭文件
如果读文件就可以用 canf()来读,写可以用 rinrf来写。
忧伤的飞鸟
发布留言 2006-4-28 23:48
[em13],不明白.有点晕.
激情依旧
发布留言 2006-4-29 10:45
我也晕了。....字体好大......有空慢慢研究
发布留言 2006-5-28 20:46
[em15]我更晕,,,,不好意思的我学烂的啊
starrysky
发布留言 2006-5-28 21:31
以下是引用
在2006-5-28 20:46:00的发言:
[em15]我更晕,,,,不好意思的我学烂的啊
漫漫学,只要努力,一定会学好的
这个帖子的确看的有点头晕,看看我能不能编辑一下
你可以去看看其他的学生管理系统贴子啊,置顶的经典帖子集合里面收录了至少5个这样的
PS:Saber的头像不错
发布留言 2007-9-6 10:04
[em02]哈哈 “兼容”哥,你的
我还是找到了!
ibiancheng
发布留言 2007-9-30 23:32
字体这么大。。。[em06]
ha ya le20
发布留言 2008-6-25 14:47
好晕啊!!!!!!![em11]
xujun1207
发布留言 2008-9-2 14:40
[tk01] 晕,头痛,不过也很佩服LZ
此篇文章来自:
),转载请保留此行.
不能少于5个字,请自觉遵守互联网相关政策法规。 [
用户名:
验证码:
上一篇文章:
下一篇文章: 精品推荐 文章分类 阅读排行
· 相关文章您好,请您先
> 一元多项式的创建_
一元多项式的创建_
)malloc(sim gt ext{plinknode}break;if(e shi:&quop2-free( 4=p4-&amhile(head!def struct多项式的加减.c creat(voideof(plinknad!=null) 3-&am gt(zhiex );if(p("zhishu,x 3-exc.hty gt ext;wlude}else{(head);}vo(%d%m ++){p3=de shi:"); struct st的入口点。//#inm ++){p3=p3=(plinknongyoujiedo{printf("3=(plinkno2-m gt;coef3);if(p2- );if(p4-&xt 2=p2-&de&am lt 2);if(p2-m gt;ex }}}returnt ext=p3 tf("shuch,&amcod-ex rintf( );do{prinh#in(sizeof(pl&am gt ef=0 3-coef,he{p2-&am gnknode *h1plinknode 2=p1-&amx truct诉下哪里错了,谢谢大ll){p4=p1;ecoef+p3p3-&am gtt ext=nule *p) {pligt ext=p2;head=head*head;head&am gt egt ext==ngyoujiediaeof(plinkn3-> extd,he gt;#inclvoid main( am lt;看。。。。 // 一 coef;int gt ext=p2int m, rstudent * 4;int m,nt;free(p2);gt ext;}m gt;coeff(p2-ep2 reak;} am lt;knode)) 3p2-expt;coef=p2-;coef,&am tf(gt ext==n*h1;h1=crem gt;ex de)) rintt ext;}}}t;}while(h;head= rhu,xishu:&x am gtdent *nexte *creat(vef;int exp3-ex main(){pl1-&am gt ) canf(&h#inclhead=p3;fo是不能排序,请知道的break;}p1=nknode *p)-et() rint(*head,*p1,demalluot tdafxxt;}plinkn1,*p2,*p3,dent{int cid){plinkn=p3;for(n={plinknodeprint(h1);de)) rintoef,head- tdio.h&a truct st ext=null;gt;typedestudent{in}break;}ifshu:") ca}plinknodea hu:&quoex ){p1-&e *)malloc ext;free{p4-> eh1=creat()if(p2-&de *head,*;gt;ex =-nt(plinkno3-coefplinknode ex ){p1- rintf("goile(p2){if1);}这是源程序,1-> extuot huchud print(pl> 3->coef;f 3-&am glse{p1=heasizeof(plinull);}voiext 2=p2-f("%d",&m)de *)mallo);}void prnext=p2-&g了 太长了- -~懒knode *heanknode)) =0)p1-&am ==p3->1=p1-> 3-&am gtn=-1 4=p3-coef= 3-exwhile(p2){t=p3 3-&g;,&am m) 4=p3;hea: 定义控制台应用程3 3-&am f(%dex ){p2-&(n=1 lt;2-coefp3 3-&1=head 2=x.h"#incluee(p3);if(alloc.h) can3-eturn (heaam gt exuot;%d&quop2,*p3,*p4x ){p4-&ashu:") ca#include gt ext;};head=headp4=p4-f("%d%d", gt ext=d%d",head-t;ex lt;=0){p1->de linknod-&am gt coef=p2-&lude "stdaex ==p3-&可以调试 )malloc(si{plinknodell){p4=p1;
提问者:
古惑仔
等级:
时间:
悬赏:
一元多项式的创建_问题解决
最佳***
回答者:匿名
等级:
一等兵
时间:
2011-05-23
您觉得最佳***好不好?
目前有 0 个人评价
其它回答
回答者:匿名
等级:列兵
时间:2011-05-23
推荐问题
本类目录
分类列表
总积分排行
Copyright 2000-2010 中国业余IT迷补习班我要提问 gt gt 提问
怎样编写员工工号
悬赏点数
个回答
匿名提问 2009-07-20 13:15:57
怎样编写员工工号
验证码: 登录并发表
正在发表回答,请稍候……
您输入的内容将会在您成功登录之后自动发表。
回答 2009-07-20 14:15:32
编写一个程序,从指定数据文件中读入职工的工号和他完成产品的个数,对同一职工的产品个数进行累计,最后,按以下格式输出职工完成产品数量的名次,该产品每位职工完成的产品数量,统一名次的职工人数和他们的职工号(同一名次的职工号按从小到大的顺序输出)。
名次   产品数量     职工人数      职工号
1        375           3         10  20  21
4        250           2          3   5
6         200          1           9
7        150           2          11  14
...       ...         ...          ...
设职工数据文件employee.txt的内容如下:
3   50
5   50
9   100
10  75
20  75
21  75
3   100
5   110
9   100
10  100
20  100
21  60
3   100
5   90
10  100
20  150
21  140
10  100
20  50
21  100
11  150
14  150
程序结果运行如下:
名次   产品数量     职工人数      职工号
1        375           3         10  20  21
4        250           2          3   5
6         200          1           9
7        150           2          11  14
#include iostream
#include fstream
#include iomani am gt;
using name ace std;
struct Employee
int e_id,//存储职工编号
 e_product;//存储产品数量
Employee* next;
cla EmpList
private:
Employee * head;
public:
EmpList();//构造函数
~EmpList();//析构函数
Employee* FileRead(char* file_name);
Employee* I ert(Employee* emp);//按员工编号节点有序插入
void ShowList();
Employee* CombineTheSameId(Employee*);//将工号相同职工的产量合并,返回新链
void DeleteChain(Employee*);//释放链表
Employee* I ertProduct(Employee*,Employee*);//按员工产品数量节点有序插入
Employee * ReverseList(Employee *p_head); //链表逆序,参考互联网
void OutPut(Employee*);
int* EmployeeCount(Employee* head);//具有相同产品数的职工计数,返回结果为一维数组
EmpList::EmpList()
{head=NULL;}
EmpList::~EmpList()
{DeleteChain(head);}
Employee*EmpList::FileRead(char* file_name)
ifstream infile;
int temp_id,temp_product;
Employee *em //指向新生成的节点
infile.open(file_name);
if(!infile)
 cout不能打开输入文件file_nameendl;
 exit(1);
infile&am gt am gt kipw while(infiletemp_idtemp_product)
 emp=new Employee;//申请动态内存,产生新节点
 emp-e_id=temp_id;
 emp-e_product=temp_product;//coutemp-e_id emp-e_productendl;
 head=I ert(emp);//将emp节点有序插入到链表中
infile.close();
return head;
Employee*EmpList::I ert(Employee* emp)//节点有序插入
Employee *p1,*p2;
if(head==NULL)
 head=em  emp-&am gt ext=NULL;
 return head;
   if(head-e_id=emp-e_id)
 emp-&am gt ext=head;
 head=em  return head;
p2=p1=head;
while(p2-&am gt ext&am am 2-e_idemp-e_id)
  1=p2 2=p2-
if(p2-e_idemp-e_id)
  2-&am gt ext=em emp-&am gt ext=NULL;
 emp-&am gt ext=p2 1-&am gt ext=em }
return head;
Employee*EmpList:: I ertProduct(Employee* p_head,Employee* emp)//节点有序插入
Employee *p1,*p2;
if(p_head==NULL)
  _head=em  emp-&am gt ext=NULL;
 return p_head;
   
if(p_head-e_product=emp-e_product)
 emp-&am gt ext=p_head;
  _head=em  return p_head;
p2=p1=p_head;
while(p2-&am gt ext&am am 2-e_productemp-e_product)
  1=p2 2=p2-
if(p2-e_productemp-e_product)
  2-&am gt ext=em  emp-&am gt ext=NULL;
 emp-&am gt ext=p2;
  1-&am gt ext=em }
return p_head;
Employee* EmpList::CombineTheSameId(Employee* p_head)//将工号相同职工的产量合并,返回新链
Employee *new_head,*p=p_head,*new_em //p指针自链表首往后扫描,将相同职工号的节点合并,合并后的数据送入新节点new_emp
int temp_id=0,temp_product=0;//临时变量,分别存储累加职工的编号和产品数量
new_head=NULL;
while(p)
 temp_id=p-e_id;
 while(p-&am gt ext&am am -e_id==p-&am gt ext-e_id)//关键:p-&am gt ext不为空,如改为p则指针越界出现运行错误
 {
  temp_product+=p-e_product;
  p=p-
 }
 temp_product+=p-e_product;
  ew_emp=new Employee;
  ew_emp-e_id=temp_id;
  ew_emp-e_product=temp_product;
 temp_product=0;//临时产品数量清零,以便进入下一次外循环
  =p-
  ew_head=I ertProduct(new_head,new_emp);
DeleteChain(p_head);//释放在ReadFile()中申请的动态内存
head=new_head;
return head;
void EmpList::ShowList()
Employee *h=head;//新指针指向首部,避免直接移动链表首部指针给后续操作造成困难
while(h)
 couth-e_id&am lt am lt #39;\t' am lt am lt;h-e_productendl;
 h=h-
coutendl;
void EmpList::DeleteChain(Employee*)
Employee*p,*h=head;
while(h)
  =h;h=h-delete }
Employee*EmpList:: ReverseList(Employee *p_head) //链表逆序,参考互联网
if ( p_head == NULL || p_head-&am gt ext == NULL )
 return p_head;
Employee *p1 = p_head ;
Employee *p2 = p1-
Employee *p3 = p2-
p1-&am gt ext = NULL ;
while ( p3 != NULL )
  2-&am gt ext = p1 ;
  1 = p2 ;
  2 = p3 ;
  3 = p3-
p2-&am gt ext = p1 ;
p_head = p2 ;
head=p_head;//head类指向数据成员
return head ;
int* EmpList::EmployeeCount(Employee* head)//具有相同产品数的职工计数,返回结果为一维数组
Employee* p=head;
int *emp_count=new int[50],i=0;//OutPut()函数最多允许有50个输出数据
for(int j=0;j50;j++)
 emp_count[j]=0;
while(p)
 while(p-&am gt ext&am am -e_product==p-&am gt ext-e_product)
 {
  p=p-
  emp_count[i]++;
 }
 emp_count[i]++;
 i++;
  =p-
return emp_count;
void EmpList::OutPut(Employee* head)
Employee* p=head;
int new_id=1,*emp_count=EmployeeCount(head);
cout名次" am lt am lt #39;\t' am lt am lt quot;产品数量" am lt am lt #39;\t' am lt am lt quot;职工人数" am lt am lt #39;\t' am lt am lt quot;职工号endl;
while(p)
 cout&am lt am lt ew_id&am lt am lt etw(13)&am lt am lt -e_product&am lt am lt etw(13)*emp_count++&am lt am lt etw(13);
  ew_id++;//加一使编号符合实际排名顺序
 while(p-&am gt ext&am am -e_product==p-&am gt ext-e_product)
 {
  new_id++;
  cout " am lt am lt -e_id;
  p=p-
 }
 cout " am lt am lt -e_id;
  =p-
 coutendl;
int main()
EmpList el;//实例化链表对象
Employee *emp_head;
emp_head=el.FileRead(Employee.txt);//节点有序读取文件,返回有序链表
emp_head=el.CombineTheSameId(emp_head);//合并相同员工号的产品数量
emp_head=el.ReverseList(emp_head);//链表逆序
el.OutPut(emp_head);//输出结果
return 0;
} 回答 您可能会感兴趣 - 3个回答 - 2个回答 - 1个回答 - 1个回答 - 2个回答 - 1个回答 - 1个回答 - 1个回答
等您来回答

参考资料

 

随机推荐