《面向对象程序设计》课程设计报告 职工档案管理.docx
《《面向对象程序设计》课程设计报告 职工档案管理.docx》由会员分享,可在线阅读,更多相关《《面向对象程序设计》课程设计报告 职工档案管理.docx(35页珍藏版)》请在冰点文库上搜索。
![《面向对象程序设计》课程设计报告 职工档案管理.docx](https://file1.bingdoc.com/fileroot1/2023-5/6/f538f506-8914-4fe1-8eb7-0c0f19edcd4d/f538f506-8914-4fe1-8eb7-0c0f19edcd4d1.gif)
《面向对象程序设计》课程设计报告职工档案管理
《面向对象程序设计》
课程设计报告
二O一三年九月六日
职工档案管理系统设计
一、课程设计问题描述
职工档案管理是高等学校教务管理的重要组成部分,其内容较多,为了简化计论,要求设计的管理系统能够完成以下六种功能:
(1)登记职工纪录;
在程序开始运行时,因为资料库为空,所以会要求输入准备添加的人数进行逐一添加,如果没有登记的迹象,可以键入“0”。
(2)添加职工个人信息;
直接进行职工个人信息的添加。
(3)显示职工个人信息;
通过find()函数进行查找。
该函数比较简单,通过循环一次比较Per[n].num是否与你输入的num是否相等,如果相等,则输入到屏幕上,如果未找到任何匹配的员工,则显示“未找该员工”。
(4)查找职工个人信息;
通过findlist()函数进行查找。
查找可以按照职工的编号和姓名两点进行查找,如果没有该员工信息,系统会弹出“无该员工信息”的提示。
(5)打印职工个人信息;
对职工信息进行显示,包括职工的编号,姓名,性别,出生年月,所在部门,职称,工资级别,电话等信息。
方便对员工了解。
(6)保存职工个人信息;
保存员工的信息,即为将当前所有的员工的信息存入到worker.txt中。
这里我们采用的是C++的ofstream的写入文件的对象进行控制。
(7)选择退出;
用户可以键入“0”退出职工信息管理系统。
二、课程设计目的和要求
目的:
经过一个学期的《C++面向对象程序设计》课程的学习,已经有了一定地程序设计基础,但是要学好C++面向对象程序设计这门课程,不仅要认真阅读课本知识和从事课堂学习,更重要的是要进行上机实践,通过上机实践才能增强和巩固知识。
完成题目所要求的全部功能,并加入本组自己的设计风格,在界面友好的基础上,增加一些附加功能,使得功能更为强大,最终得到一个可靠性高,易于操作的职工信息管理的系统。
要求:
1、用C++语言实现程序设计;
2、利用单向链表实现职工信息的数据结构设计(每个节点管理一位职工信息);
3、界面友好(良好的人机交互),程序加必要的注释。
三、系统设计(算法分析)
1、编写要求:
1)先声明职工人员结构,该结构中包含编号、姓名、出生年月、性别、职称、部门,工资级别,电话等成员变量,并定义人员结构数组;
2)编写主函数,要求提供一个界面,允许工作人员输入、修改和显示员工信息;
3)给出某个员工的编号活着姓名,可对该员工信息进行查找,若找到,显示相应信息,否则显示“该员工不存在”。
4)将所有职工信息保存在磁盘上。
2、设计思想描述
使用单向链表指针,能够管理简单的职工信息,是一个设计较为人性化的操作系统。
首先,建立职工的信息库。
然后根据提示,选择“按1继续,按2退出”。
若选择继续操作,则会出现菜单栏,可以选择进行职工信息的插入,查询,删除,显示,保存等操作和系统的退出。
操作完毕后,再次选择“按1继续,按2退出”……
否则,退出操作程序。
系统由头文件名,一个类,七个自定义函数和一个主函数构成。
头文件名:
#include
#include//包含exit
(1)函数
#include//包含字符串的比较函数strcmp
类:
ClassCWorker
八个自定义函数:
intmenu()//提供菜单选项,供用户选择各个功能模块
voidCreat(CWorker)//建立职工的信息库
voidAddlist(CWorker)//插入职工信息
voidFindlist(CWorker)//查询职工信息
voidDellist(CWorker)//删除职工信息
voidShowlist(CWorker)//显示所有职工信息
voidSave()//保存所有职工信息
voidOut()//退出系统
主函数:
intmain()//将各函数组合成一个有机的整体,实现各个函数的调用
3、流程图
4、各函数的功能和实现
职工信息管理系统的相关功能由对应的函数来实现。
(1)职工注册登记
voidCreat(CWorker**a)//creat函数的定义,建立职工信息库
{
intn=0;
inti=0;
*a=NULL;
CWorker*b;
cout<<"职工人数,请输入:
\n";
cin>>n;
cout<for(i=1;i<=n;i++)
{
b=newCWorker;//分配内存空间
if(b==NULL)
{
cout<<"内存空间用完,退出!
\n";
exit
(1);
}
cout<<"请输入第"<
(以空格隔开)\n";
cin>>b->num>>b->name>>b->sex>>b->title>>b->part>>b->salary>>b->birth>>b->tel;
cout<b->next=NULL;//建立链表
if(*a==NULL)
*a=b;
else
{
CWorker*p=*a;
while(p->next!
=NULL)
p=p->next;
p->next=b;//新建结点
}
}
cout<<"储存完毕!
\n";
}
(2)添加职工信息
voidCWorker:
:
Addlist(CWorker**a)//addlist函数的定义,插入职工信息
{
CWorker*b;
b=newCWorker;//分配内存空间
if(b==NULL)
{
cout<<"内存空间用完,退出!
\n";
exit
(1);
}
cout<<"请输入职工的编号,姓名,性别,职称,部门,工资,生日,电话:
(以空格隔开)\n";
cin>>b->num>>b->name>>b->sex>>b->title>>b->part>>b->salary>>b->birth>>b->tel;
b->next=NULL;//建立链表
if(*a==NULL)
*a=b;
else
{
CWorker*p=*a;//新建指针变量
while(p->next!
=NULL)
p=p->next;
p->next=b;
}
cout<<"插入完毕!
\n";
}
(3)修改职工信息
voidCWorker:
:
Dellist(CWorker**a)//dellist函数的定义,删除职工信息
{
charnum1[20];
charname1[20];
inti=0,n;
CWorker*cp=*a;
CWorker*ap=NULL;
cout<<"===========================\n";
cout<<"1、按编号删除\n";
cout<<"2、按姓名删除\n";
cout<<"===========================\n";
cout<<"请选择:
\n";
cin>>n;
if(n==1)
{
cout<<"请输入要删除职工的编号:
\n";
cin>>num1;
if(cp==NULL)
{
cout<<"信息库为空,不能删除!
\n";
return;//退出
}
while(cp!
=NULL)
{
i++;//节点数目增加
if(num1==cp->num)//核对职工信息
break;
ap=cp;
cp=cp->next;
}
if(cp==NULL)
{
cout<<"无该职工信息!
\n";
return;//退出
}
if(i==1)
*a=cp->next;
else
ap->next=cp->next;
deletecp;
cout<<"已经删除成功!
\n";
}
elseif(n==2)
{
cout<<"请输入要删除职工的姓名:
\n";
cin>>name1;
if(cp==NULL)
{
cout<<"信息库为空,不能删除!
\n";
return;//退出
}
while(cp!
=NULL)
{
i++;//结点数目增加
if(strcmp(name1,cp->name)==0)
break;
ap=cp;
cp=cp->next;
}
if(cp==NULL)
{
cout<<"无该职工信息!
";
return;//退出
}
if(i==1)
*a=cp->next;
else
ap->next=cp->next;
deletecp;
cout<<"已经删除成功!
\n";
}
}
(4)打印所有职工信息
voidCWorker:
:
Showlist(CWorker*a)//showlist函数的定义,显示所有职工信息
{
if(a==NULL)
cout<<"无信息,请先存储!
\n";
while(a!
=NULL)
{
cout<<"编号\t姓名\t\t性别\t职称\t部门\t工资\t生日\t\t电话"<cout<num<<"\t"<name<<"\t"<<"\t"<sex<<"\t"<title<<"\t"
<part<<"\t"<salary<<"\t"<birth<<"\t"<tel;
a=a->next;
cout<}
}
(5)查找职工信息
voidCWorker:
:
Findlist(CWorker*a)//findlist函数的定义,查询职工信息
{
charnum1[20];
charname1[20];
inti=0,n;
cout<<"===========================\n";
cout<<"1、按编号查询\n";
cout<<"2、按姓名查询\n";
cout<<"===========================\n";
cout<<"请选择:
\n";
cin>>n;
if(n==1)
{
cout<<"请输入要查找职工的编号:
\n";
cin>>num1;
while(a!
=NULL)
{
if(strcmp(num1,a->num)==0)//核对职工信息
{
cout<<"编号\t姓名\t\t性别\t职称\t部门\t工资\t生日\t\t电话"<cout<num<<"\t"<name<<"\t"<<"\t"<sex<<"\t"<title<<"\t"
<part<<"\t"<salary<<"\t"<birth<<"\t"<<"t"<tel;
break;
}
else
a=a->next;
}
if(a==NULL)
cout<<"无该职工信息!
\n";
}
elseif(n==2)
{
cout<<"请输入要查找职工的姓名:
\n";
cin>>name1;
while(a!
=NULL)
{
if(strcmp(name1,a->name)==0)//核对职工信息
{
cout<<"编号\t姓名\t\t性别\t职称\t部门\t工资\t生日\t\t电话"<cout<num<<"\t"<name<<"\t"<<"\t"<sex<<"\t"<title<<"\t"
<part<<"\t"<salary<<"\t"<birth<<"\t"<<"\t"<tel;
break;
}
else
a=a->next;
}
if(a==NULL)
cout<<"无该职工信息!
\n";
}
}
(6)退出系统
voidOut()//out函数的定义,退出系统
{
cout<<"再见!
"<exit
(1);
}
(7)保存职工信息
CWorFile:
:
CWorFile(char*filename)
{
thefile.open(filename,ios:
:
in|ios:
:
out|ios:
:
trunc);
if(!
thefile)
{
cout<"<(1);
}
}
CWorFile:
:
~CWorFile()
{
if(thefile.is_open())thefile.close();
}
voidCWorFile:
:
Add(CWorker*worker)
{
CWorker*tmp=worker;
//将文件指针定位到结尾,然后添加
thefile.seekp(0,ios:
:
end);
while(tmp!
=NULL)
{
thefile<<*tmp;
tmp=tmp->next;
}
}
voidCWorFile:
:
List()
{
CWorkerworker;
//将文件指针定位到头文件,然后显示
thefile.clear();
thefile.seekg(0);
inti=0;
while(thefile>>worker)
{worker.Print(i+1);i++;}
}
六、困难及解决方案
1)困难1:
链表指针和多级指针及内存空间的开辟和释放等在程序中的多次运用,易出现很多漏洞,造成混乱而无法运行。
解决方案:
运用排除法,经过好几天的各个方面的排除,最后将问题彻底的清理。
2)困难2:
不知道怎样将菜单表格化,那样更直观。
解决方案:
使用大量的字符拼图组合,输出形成一个美观实用的菜单表格目录。
3)困难3:
在保存职工信息时不知道怎么用ofstream和switch语句结合起来。
并且容易出现乱码。
解决方案:
翻阅参考书和网上搜索,通过库函数将int型转换为ascii码,进行不停的尝试。
五、程序源代码
#include
#include
#include
#include
#include
#include
usingnamespacestd;
classCWorker;
ostream&operator<<(ostream&os,CWorker&worker);
istream&operator>>(istream&is,CWorker&worker);
intGetValidSelect(intbeginno,intendno){
intn=-1;
for(;;)
{
cin>>n;
if(cin.fail()){
cin.clear();
cin.sync();
n=-1;
}
if(nendno){
cout<<"\n输入错误,重选"<";//超出输入范围
}else{
break;//跳出循环体
}
}
returnn;
}
voidmenu()
{
cout<cout<<"\t******************************************************"<cout<<"\t****"<cout<<"\t**职工信息管理系统主菜单**"<cout<<"\t****"<cout<<"\t**0.退出**"<cout<<"\t**1.职工信息添加**"<cout<<"\t**2.职工信息显示**"<cout<<"\t**3.职工信息查找**"<cout<<"\t**4.职工信息修改**"<cout<<"\t**5.职工信息保存**"<cout<<"\t****"<cout<<"\t**¤ ╭⌒╮╭⌒╮**"<cout<<"\t**╱◥██◣╭╭⌒╮好好学习天天向上**"<cout<<"\t**︱田︱田田|╰----------------------------- **"<cout<<"\t**╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬**"<cout<<"\t****"<cout<<"\t****"<cout<<"\t******************************************************"<cout<cout<<"请选择0~5的数字使用功能"<}
classCWorker
{
public:
CWorker(){
next=NULL;
memset(name,0,sizeof(name));
memset(num,0,sizeof(num));
memset(sex,0,sizeof(sex));
memset(birth,0,sizeof(birth));
memset(part,0,sizeof(part));
memset(title,0,sizeof(title));
memset(tel,0,sizeof(tel));
salary=0;
}
CWorker(char*num,char*name,char*sex,char*title,char*part,intsalary,char*birth,char*tel)
{
CWorker();
strncpy(this->num,num,20);
strncpy(this->name,name,20);
strncpy(this->sex,sex,20);
strncpy(this->title,title,20);
strncpy(this->part,part,20);
this->salary=salary;
strncpy(this->birth,birth,20);
strncpy(this->tel,tel,20);
}
CWorker(CWorker&one)
{
CWorker();
strncpy(this->num,one.num,20);
strncpy(this->name,one.name,20);
strncpy(this->sex,one.sex,20);
strncpy(this->title,one.title,20);
strncpy(this->part,one.part,20);
this->salary=one.salary;
strncpy(this->birth,one.birth,20);
strncpy(this->tel,one.tel,20);
}
char*GetName()
{returnname;}
~CWorker(){}
voidPrint(intn=-1);
voidInput();
friendostream&operator<<(ostream&os,CWorker&worker);
friendistream&operator>>(istream&is,CWorker&worker);
voidCreat(CWorker**a)//creat函数的定义,建立职工信息库
{
intn=0;
inti=0;
*a=NULL;
CWorker*b;
cout<<"职工人数,请输入:
\n";
cin>>n;
cout<for(i=1;i<=n;i++)
{
b=newCWorker;//分配内存空间
if(b==NULL)
{
cout<<"内存空间用完,退出!
\n";
exit
(1);
}
cout<<"请输入第"<
(以空格隔开)\n";
cin>>b->num>>b->name>>b->sex>>b->title>>b->part>>b->salary>>b->birth>>b->tel;
cout<b->next=NULL;//建立链表
if(*a==NULL)
*a=b;
else
{
CWorker*p=*a;
while(p->next!
=NULL)
p=p->next;
p->next=b;//新建结点
}
}
cout<<"储存完毕!
\n";
}
voidOut()//out函数的定义,退出系统
{
cout<<"再见!
"<exit
(1);
}
voidShowlist(CWorker*a);
voidAddlist(CWorker**a);
voidFindlist(CWorker*a);
voidDellist(CWorker**a);
public:
CWorker*next;//创建指针
protected:
charname[20];
charnum[20];
charsex[20];
charbirth[20];
charpart[20];
chartitle[20];
chartel[20];
intsalary;
};
voidCWo