高职学院
C++程序设计语言上学期
课 程 设 计 报 告
(2011 -2012第1学期)
课程设计类型:C语言程序设计
题目:人员信息管理系统
学号:
姓名:
专业:计算机应用基础
指导教师:
课程设计日期:2012.12.23-2012.12.27.
目 录
1. 问题分析... 1
2. 总体设计... 1
2.1 功能分析·· 1
3. 详细设计... 2
3.1 程序结构图·· 2
3.2 程序类结构图·· 2
3.3 程序类结构图·· 3
4. 功能测试... 4
4.1 本系统的主界面·· 4
4.2 录入功能的主界面·· 4
4.3 显示功能的主界面·· 5
4.4 查找功能的主界面·· 5
4.5 修改功能的主界面·· 6
4.6 删除功能的主界面·· 6
4.7 清理功能的主界面·· 7
4.8 退出功能的主界面·· 7
5. 课设小结... 7
参 考 文 献... 8
附录:源代码清单... 8
1. 问题分析
1.1 问题描述
1.题目《人员信息管理系统》设计
2.设计说明与要求
(1) 公司主要有4类人员:经理、技术人员、销售员、销售经理,要求存储这些人的姓名、年龄、工资信息。
(2) 工资的计算方法
A、 经理:固定为8000元;
B、技术员:工作时间*每小时酬金(100RMB);
C、销售员:4%提成;
D、 销售经理:1%提成+固定工资(5000RMB);
(3) 实现功能
① 录入:输入各种数据,并录入TXT文件保存;
② 显示:显示员工的数据信息;
③ 查找:查找员工的数据信息;
④ 修改:修改员工的数据信息;
⑤ 删除:删除员工的数据信息;
⑥ 退出:退出本系统;
⑦ 清理存储文件:清理系统产生的TXT文件;
2. 总体设计
2.1 功能分析
使用面向对象的程序设计思想进行分析,整个系统涉及两大类信息和操作,公司,人员。所以系统主要涉及两个大类:公司类business、人员类person。系统的总体框架就是公司类,人员类的定义;主函数中定义一个公司对象,循环显示主菜单并根据用户选择调用公司类的相应方法(成员函数)。
3. 详细设计
3.1 程序结构图
3.2 程序类结构图
3.3 程序类结构图
4. 功能测试
4.1 本系统的主界面
4.2 录入功能的主界面
4.3 显示功能的主界面
4.4 查找功能的主界面
4.5 修改功能的主界面
4.6 删除功能的主界面
4.7 清理功能的主界面
4.8 退出功能的主界面
5. 课设小结
根据课程设计的要求,我思考出了自己的课题,我用本学期所学的C++面向对象的知识来编写程序。我利用面向对象的方法以及C++的编程思想来完成系统的设计,在设计的过程中,建立清晰的层次,当然在调试过程中我也遇到了许多问题。
本程序由雇员这个基类派生出多个派生类,并且调用多个函数。主函数主要运用选择结构。派生类中的保护类数据要通过定义公有类型的函数来从类外调用。和一些相当复杂的算法,自己看了都乱,头都晕。不过,我相信,不经历风雨怎么能见彩虹。在解决了这一切后,我有一种:天将降大任于斯人也,必先劳其筋骨,饿其体肤的感觉!
参 考 文 献
1. 钱能主编,C++程序设计教程,清华大学出版社,2000.11
2. 戴锋编著,Visual C++程序设计基础,清华大学出版社,2001.4
3. 施平安主编,C++程序设计教程(第四版),清华大学出版社,2004.3
4. 林丽闽主编,标准C++程序设计教程,电子工业出版社,2003.6.1
5. 谭浩强主编,C++程序设计,清华大学出版社,2004.6
附录:源代码清单
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
class person
{
public:
char name[20],post[20],hour[20];
int age,number;
};
class business :public person
{
public :
int time;
}
;
//经理
class mgr : public person
{
public:
int monthpay;
mgr :: mgr()
{
monthpay=8000 ;
}
void out()
{
cout<<"请输入职工的编号:";
cin>>number ;
cout<<"请输入职工的姓名:";
cin>>name ;
cout<<"请输入职工的年龄:";
cin>>age ;
cout<<"该职工的月薪为:"<<monthpay<<endl;
}
void in()
{
cout<<"编号:"<<number<<' '<<"姓名:"<<name<<' '<<"年龄:"<<age<<' '<<"职称:"<<"经理 "<<' '<<"月薪:"<<monthpay<<endl;
}
};
//技术人员
class technician :public person
{
public:
int hourlyRate ;
//每小时酬金
int workHours ;
//当月工作时数
int pay;
technician :: technician()
{
hourlyRate=100 ;
};
void in()
{
cout<<"编号:"<<number<<' '<<"姓名:"<<name<<' '<<"年龄:"<<age<<' '<<"职称:"<<"技术人员"<<' '<<"月薪:"<<pay<<endl ;
}
void out()
{
cout<<"请输入职工的编号:";
cin>>number ;
cout<<"请输入职工的名字:";
cin>>name ;
cout<<"请输入工作的小时:";
cin>>workHours ;
cout<<"请输入职工的年龄:";
cin>>age ;
pay=hourlyRate*workHours;
cout<<"该职工的月薪为:"<<pay<<endl;
}
};
//销售经理
class sell :public business
{
public:
int phpay,monthpay;
sell :: sell()
{
phpay=1,monthpay=5000;
}
void in()
{
cout<<"编号:"<<number<<" "<<"姓名:"<<name<<" "<<"销售额:"<<time<<" "<<"年龄:"<<age<<" "<<"职称:"<<"销售经理"<<" "<<"月薪:"<<pay()<<endl ;
}
int pay()
{
return(phpay*time+monthpay);
}
void out()
{
cout<<"请输入职工的编号:";
cin>>number ;
cout<<"请输入职工的名字:";
cin>>name ;
cout<<"请输入销售额 :";
cin>>time ;
cout<<"请输入职工的年龄:";
cin>>age ;
cout<<"职工的月薪为:"<<pay()<<endl;
}
};
//推销员
class bagman :public business
{
public:
int phpay ;
bagman :: bagman()
{
phpay=4;
}
void in()
{
cout<<"编号:"<<number<<" "<<"姓名:"<<name<<" "<<"销售额:"<<time<<" "<<"年龄:"<<age<<" "<<"职称:"<<"推销员 "<<" "<<"年薪:"<<pay()<<endl ;
}
int pay()
{
return(phpay*time);
}
void out()
{
cout<<"请输入职工的编号:";
cin>>number ;
cout<<"请输入职工的名字:";
cin>>name ;
cout<<"请输入销售额 :";
cin>>time ;
cout<<"请输入职工的年龄:";
cin>>age ;
cout<<"该职工的月薪为:"<<pay()<<endl;
}
};
//输入函数
void write1()
{
mgr p;
p.out();
ofstream myfile("f1.txt",ios :: binary|ios :: ate);
myfile.write((char*)&p,sizeof p);
myfile.close();
}
void write2()
{
technician p;
p.out();
ofstream myfile("f2.txt",ios :: binary|ios :: ate);
myfile.write((char*)&p,sizeof p);
myfile.close();
}
void write3()
{
sell p;
p.out();
ofstream myfile("f3.txt",ios :: binary|ios :: ate);
myfile.write((char*)&p,sizeof p);
myfile.close();
}
void write4()
{
bagman p;
ofstream myfile("f4.txt",ios :: binary|ios :: ate);
p.out();
myfile.write((char*)&p,sizeof p);
myfile.close();
}
void build()
{
cout<<endl;
cout<<" ******************请选择职工的信息****************** "<<endl;
cout<<" ** 1.经理 ** "<<endl;
cout<<" ** 2.技术人员 ** "<<endl;
cout<<" ** 3.销售经理 ** "<<endl;
cout<<" ** 4.推销员 ** "<<endl;
cout<<" **************************************************** "<<endl;
cout<<"请输入选择:"<<endl;
char ch;
cin>>ch;
while(ch!='N'&&ch!='n')
{
switch(ch)
{
case '1' :
write1();
break ;
case '2' :
write2();
break ;
case '3' :
write3();
break ;
case '4' :
write4();
break ;
default :
cout<<"ERROR!!"<<endl;
break ;
}
cout<<"是否继续使用录入功能:(Y/N)?";
cin>>ch;
if(ch=='Y'||ch=='y')
{
cout<<"请输入选择:"<<endl;
cin>>ch;
}
}
}
//显示函数
void show1()
{
ifstream myfile("f1.txt",ios :: binary|ios :: out|ios :: in);
mgr p;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
p.in();
myfile.read((char*)&p,sizeof p);
}
myfile.close();
}
void show2()
{
ifstream myfile("f2.txt",ios :: binary|ios :: out|ios :: in);
technician p;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
p.in();
myfile.read((char*)&p,sizeof p);
}
myfile.close();
}
void show3()
{
ifstream myfile("f3.txt",ios :: binary|ios :: out|ios :: in);
sell p ;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
p.in();
myfile.read((char*)&p,sizeof p);
}
myfile.close();
}
void show4()
{
ifstream myfile("f4.txt",ios :: binary|ios :: out|ios :: in);
bagman p ;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
p.in();
myfile.read((char*)&p,sizeof p);
}
myfile.close();
}
void show0()
{
show1();
show2();
show3();
show4();
}
void show()
{
cout<<" **********************你正在显示********************"<<endl;
cout<<" ** 0.全部显示 **"<<endl;
cout<<" ** 1.经理 **"<<endl;
cout<<" ** 2.技术人员 **"<<endl;
cout<<" ** 3.销售经理 **"<<endl;
cout<<" ** 4.推销员 **"<<endl;
cout<<" ****************************************************"<<endl;
cout<<"请选择你要显示的职工类:"<<endl;
char c;
cin>>c ;
while(c!='N'&&c!='n')
{
switch(c)
{
case '0' :
show0();
break;
case '1' :
show1();
break;
case '2' :
show2();
break;
case '3' :
show3();
break;
case '4' :
show4();
break;
default :
cout<<"ERROR!!"<<endl;
break;
}
cout<<"是否继续使用显示功能(Y/N)?"<<endl;
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"请选择你要显示的职工类:"<<endl;
cin>>c;
}
}
}
//查找函数
void search1()
{
int m=1;
cout<<"请输入你要查找的编号:"<<endl;
int number;
cin>>number;
ifstream myfile("f1.txt",ios :: binary|ios :: out|ios :: in);
mgr p;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
if(number==p.number)
{
p.in();
myfile.close();
m=0;
}
myfile.read((char*)&p,sizeof p);
}
if(m)
cout<<"查无此人!!!"<<endl;
}
void search2()
{
int m=1;
cout<<"请输入你要查找的编号:"<<endl;
int number;
cin>>number;
ifstream myfile("f2.txt",ios :: binary|ios :: out|ios :: in);
technician p;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
if(number==p.number)
{
p.in();
myfile.close();
m=0;
}
myfile.read((char*)&p,sizeof p);
}
if(m)
cout<<"查无此人!!!"<<endl;
}
void search3()
{
int m=1;
cout<<"请输入你要查找的编号:"<<endl;
int number;
cin>>number;
ifstream myfile("f3.txt",ios :: binary|ios :: out|ios :: in);
sell p ;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
if(number==p.number)
{
p.in();
myfile.close();
m=0;
}
myfile.read((char*)&p,sizeof p);
}
if(m)
cout<<"查无此人!!!"<<endl;
}
void search4()
{
int m=1;
cout<<"请输入你要查找的编号:"<<endl ;
int number;
cin>>number;
ifstream myfile("f4.txt",ios :: binary|ios :: out|ios :: in);
bagman p ;
myfile.read((char*)&p,sizeof p);
while(!myfile.eof())
{
if(number==p.number)
{
p.in();
myfile.close();
m=0;
}
myfile.read((char*)&p,sizeof p);
}
if(m)
cout<<"查无此人!!!"<<endl;
}
void search()
{
cout<<" *********************你正在查找*********************"<<endl;
cout<<" ** 1.经理 **"<<endl;
cout<<" ** 2.技术人员 **"<<endl;
cout<<" ** 3.销售经理 **"<<endl;
cout<<" ** 4.推销员 **"<<endl;
cout<<" ****************************************************"<<endl;
cout<<"请选择你的职称类型:"<<endl;
char c;
cin>>c;
while(c!='N'&&c!='n')
{
switch(c)
{
case '1' :
search1();
break;
case '2' :
search2();
break;
case '3' :
search3();
break;
case '4' :
search4();
break;
default :
cout<<"ERROR!!"<<endl;
break;
}
cout<<"是否继续使用查找功能(Y/N)?";
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"请选择你的职称类型:"<<endl;
cin>>c;
}
}
}
//修改函数
void repair1(void)
{
int num,i=0,k=0;
mgr*p1=new mgr[50];
cout<<"请输入你要修改的编号:";
cin>>num ;
ifstream h1("f1.txt",ios :: binary|ios :: in);
h1.read((char*)&p1[i],sizeof p1[i]);
while(!h1.eof())
{
i++;
h1.read((char*)&p1[i],sizeof p1[i]);
}
h1.close();
k=i ;
for(i=0;i<k;i++)
{
if(num==p1[i].number)
{
p1[i].out();
cout<<"修改完毕!"<<endl ;
}
}
ofstream h2("f1.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
h2.write((char*)&p1[i],sizeof p1[i]);
}
h2.close();
delete[]p1 ;
}
void repair2(void)
{
int num,i=0,k=0;
technician*p2=new technician[50];
cout<<"请输入你要修改的编号:";
cin>>num;
ifstream h2("f2.txt",ios :: binary|ios :: in);
h2.read((char*)&p2[i],sizeof p2[i]);
while(!h2.eof())
{
i++;
h2.read((char*)&p2[i],sizeof p2[i]);
}
h2.close();
k=i ;
for(i=0;i<k;i++)
{
if(num==p2[i].number)
{
p2[i].out();
cout<<"修改完毕!"<<endl;
}
}
ofstream h1("f2.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
h1.write((char*)&p2[i],sizeof p2[i]);
}
h1.close();
delete[]p2;
}
void repair3(void)
{
int num,i=0,k=0;
sell*p6=new sell[50];
cout<<"请输入你要修改的编号:";
cin>>num ;
fstream h6("f3.txt",ios :: binary|ios :: out|ios :: in);
h6.read((char*)&p6[i],sizeof p6[i]);
while(!h6.eof())
{
i++;
h6.read((char*)&p6[i],sizeof p6[i]);
}
k=i ;
h6.close();
for(i=0;i<k;i++)
{
if(num==p6[i].number)
{
p6[i].in();
cout<<"修改完毕!"<<endl;
}
}
ofstream h1("f6.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
h1.write((char*)&p6[i],sizeof p6[i]);
}
h1.close();
delete[]p6;
}
void repair4(void)
{
int num,i=0,k=0 ;
bagman*p7=new bagman[50];
cout<<"请输入你要修改的编号:";
cin>>num;
fstream h7("f4.txt",ios :: binary|ios :: out|ios :: in);
h7.read((char*)&p7[i],sizeof p7[i]);
while(!h7.eof())
{
i++;
h7.read((char*)&p7[i],sizeof p7[i]);
}
k=i;
h7.close();
for(i=0;i<k;i++)
{
if(num==p7[i].number)
{
p7[i].out();
cout<<"修改完毕!"<<endl;
}
}
ofstream h1("f7.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
h1.write((char*)&p7[i],sizeof p7[i]);
}
h1.close();
delete[]p7;
}
void repair()
{
cout<<" *********************你正在修改*********************"<<endl;
cout<<" ** 1.经理 **"<<endl;
cout<<" ** 2.技术人员 **"<<endl;
cout<<" ** 3.销售经理 **"<<endl;
cout<<" ** 4.推销员 **"<<endl;
cout<<" ****************************************************"<<endl;
cout<<"请输入你要修改的职称类型:"<<endl ;
char c;
cin>>c;
while(c!='N'&&c!='n')
{
switch(c)
{
case '1' :
repair1();
break;
case '2' :
repair2();
break;
case '3' :
repair3();
break;
case '4' :
repair4();
break;
default :
cout<<"ERROR!!"<<endl;
break;
}
cout<<"是否继续修改(Y/N)?"<<endl;
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"请输入你要修改的职称类型:"<<endl;
cin>>c;
}
}
}
void delete1()
{
int i=0,number;
ifstream myfile("f1.txt",ios :: binary|ios :: in);
mgr p[30];
myfile.read((char*)(p+i),sizeof*p);
cout<<"请输入你要删除的对象的编号:"<<endl;
cin>>number;
while(!myfile.eof())
{
if(number==p[i].number)
{
i--;
}
i++;
myfile.read((char*)(p+i),sizeof*p);
}
int k=i;
myfile.close();
ofstream file2("f1.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
file2.write((char*)(p+i),sizeof*p);
}
}
void delete2()
{
int i=0,number ;
ifstream myfile("f2.txt",ios :: binary|ios :: in);
technician p[30];
myfile.read((char*)(p+i),sizeof*p);
cout<<"请输入你要删除的对象的编号:"<<endl ;
cin>>number ;
while(!myfile.eof())
{
if(number==p[i].number)
{
i--;
}
i++;
myfile.read((char*)(p+i),sizeof*p);
}
int k=i;
myfile.close();
ofstream file2("f2.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
file2.write((char*)(p+i),sizeof*p);
}
}
void delete3()
{
int i=0,number;
ifstream myfile("f3.txt",ios :: binary|ios :: in);
sell p[30];
myfile.read((char*)(p+i),sizeof*p);
cout<<"请输入你要删除的对象的编号:"<<endl ;
cin>>number ;
while(!myfile.eof())
{
if(number==p[i].number)
{
i--;
}
i++;
myfile.read((char*)(p+i),sizeof*p);
}
int k=i;
myfile.close();
ofstream file2("f3.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
file2.write((char*)(p+i),sizeof*p);
}
}
void delete4()
{
int i=0,number;
ifstream myfile("f4.txt",ios :: binary|ios :: in);
bagman p[30];
myfile.read((char*)(p+i),sizeof*p);
cout<<"请输入你要删除的对象的编号:"<<endl;
cin>>number ;
while(!myfile.eof())
{
if(number==p[i].number)
{
i--;
}
i++;
myfile.read((char*)(p+i),sizeof*p);
}
int k=i;
myfile.close();
ofstream file2("f4.txt",ios :: binary|ios :: out);
for(i=0;i<k;i++)
{
file2.write((char*)(p+i),sizeof*p);
}
}
void delet()
{
cout<<" *********************你正在删除*********************"<<endl;
cout<<" ** 1.经理 **"<<endl;
cout<<" ** 2.技术人员 **"<<endl;
cout<<" ** 3.销售经理 **"<<endl;
cout<<" ** 4.推销员 **"<<endl;
cout<<" ****************************************************"<<endl;
cout<<"请输入你要删除对象的类型:"<<endl;
char c;
cin>>c;
while(c!='N'&&c!='n')
{
switch(c)
{
case '1' :
delete1();
break;
case '2' :
delete2();
break;
case '3' :
delete3();
break;
case '4' :
delete4();
break;
default :
cout<<"ERROR!!"<<endl;
break;
}
cout<<"是否继续使用删除功能(Y/N)?"<<endl;
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"请输入你要删除对象的类型:"<<endl;
cin>>c;
}
}
}
void manag()
{
remove("f1.txt");
remove("f2.txt");
remove("f3.txt");
remove("f4.txt");
cout<<"文件已经删除,请返回管理系统!!!"<<endl;
}
void manage()
{
char c;
cout<<" *********************你正在删除*********************"<<endl;
cout<<" ** 1.经理 **"<<endl;
cout<<" ** 2.技术人员 **"<<endl;
cout<<" ** 3.销售经理 **"<<endl;
cout<<" ** 4.推销员 **"<<endl;
cout<<" ** 5.全部删除 **"<<endl;
cout<<" ****************************************************"<<endl;
cout<<"请输入你要删除的对象:"<<endl;
cin>>c;
while(c!='N'&&c!='n')
{
switch(c)
{
case '1' :
remove("f1.txt");
cout<<"删除成功!!!"<<endl;
break;
case '2' :
remove("f2.txt");
cout<<"删除成功!!!"<<endl;
break;
case '3' :
remove("f3.txt");
cout<<"删除成功!!!"<<endl;
break;
case '4' :
remove("f4.txt");
cout<<"删除成功!!!"<<endl;
break;
case '5' :
manag();
break;
default :
cout<<"ERROR!!"<<endl;
break;
}
cout<<"是否继续使用清理功能(Y/N)?"<<endl;
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"请输入你要删除的对象:"<<endl;
cin>>c;
}
}
}
void main()
{
system("cls");
cout<<" *****************人员信息管理系统*****************"<<endl;
cout<<" ** **"<<endl;
cout<<" ** 1.录入 **"<<endl;
cout<<" ** 2.显示 **"<<endl;
cout<<" ** 3.查找 **"<<endl;
cout<<" ** 4.修改 **"<<endl;
cout<<" ** 5.删除 **"<<endl;
cout<<" ** 6.退出 **"<<endl;
cout<<" ** 0.清理存储文件 **"<<endl;
cout<<" ** **"<<endl;
cout<<" **************************************************"<<endl;
cout<<"请输入你要选择的功能(1-6):"<<endl;
char c;
cin>>c ;
while(c!='N'&&c!='n')
{
switch(c)
{
case '1' :
{
system("cls");
build();
}
break;
case '2' :
{
system("cls");
show();
}
break;
case '3' :
{
system("cls");
search();
}
break;
case '4' :
{
system("cls");
repair();
}
break;
case '5' :
{
system("cls");
delet();
}
break;
case '6' :
exit(0);
break;
case '0' :
{
system("cls");
manage();
}
break;
default:
break;
}
cout<<"是否继续使用管理系统:(Y/N)?";
cin>>c;
if(c=='Y'||c=='y')
main();
else exit(0);
}
}