c++公司人事管理.doc_第1页
c++公司人事管理.doc_第2页
c++公司人事管理.doc_第3页
c++公司人事管理.doc_第4页
c++公司人事管理.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品文档/ 852369.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include #include #include #include #include #include #include#include#includeusing namespace std;class Staff /声明员工类 protected: int num,post; char name20; float income; public: friend class Boss;/在一个非成员函数中,要想访问类的私有数据成员 /,该函数必须声明为该类的友元函数 Staff() /声明一个无参的构造函数Staff Staff (int id,char *Name,int post,double pay);/定义一个有参的构造函数,用参数的初始化表对数据成员初始化 virtual double Pay()return 0; ; Staff :Staff (int id,char *Name,int Post,double pay) /在类外定义有参构造函数 num=id; post=Post; income= pay; strcpy(name,Name); class TechniqueManager:public Staff /声明技术经理类 public: TechniqueManager(int id,char *Name,int post,double pay):Staff (id,Name,post,pay) double Pay()return income=5000; void display(); TechniqueManager() ;void TechniqueManager:display()/构造函数 Pay(); coutnum name 技术经理 incomeendl;class BusinessManager:public Staff /声明业务经理类 public: double Amount, Programe; BusinessManager(int id,char *Name,int post,double amount,double programe,double pay); void SetAmount(double s,double d); double Pay(); BusinessManager() ;BusinessManager:BusinessManager(int id,char *Name,int post,double amount,double programe,double pay):Staff (id,Name,post,pay) /构造函数 Amount=amount; Programe=programe;void BusinessManager:SetAmount(double s,double d)Amount=s;Programe=d;double BusinessManager:Pay()return income=2000+Amount*15/100+Programe*10/100;class Secretary:public Staff /声明文秘类 public:Secretary(int id,char *Name,int post,double pay):Staff (id,Name,post,pay)double Pay()return income=1500;void display(); Secretary() ;void Secretary:display() /构造函数 Pay(); coutnum name 文秘 incomeendl; class Financial:public Staff /声明财务人员类 public: Financial(int id,char *Name,int post,double pay):Staff (id,Name,post,pay) double Pay()return income=2000; void display(); Financial() ;void Financial:display() /构造函数 Pay(); coutnum name 财务 incomeendl; class Sales:public Staff /声明业务人员类 public: double Amount,Programe; Sales(int id,char *Name,int post,double amount,double programe,double pay); void SetAmount(double s,double d); virtual double Pay(); Sales() ;Sales:Sales(int id,char *Name,int post,double amount,double programe,double pay):Staff (id,Name,post,pay) /在类外定义有参构造函数 Amount=Amount;/销售额 Programe=programe;/项目额 double Sales:Pay() return income=Amount*15/100+Programe*10/100; void Sales:SetAmount(double s,double d) Amount=s;Programe=d;class Technician:public Staff /声明技术员类 public: double Line; Technician(int id,char *Name,int post,double line,double pay):Staff (id,Name,post,pay) Line=line; double Pay(); void display(); Technician();double Technician:Pay() /在类外定义无参构造函数return income=Line;void Technician:display() Pay();coutnum name 技术人员 incomeendl; class Boss / 声明老板类public: Boss(); void Add(); void Search(); void Delete(); void Modify(); void DisPlay(); Boss() ;void Boss:Add() time_t t = time(0); char tmp64; strftime( tmp, sizeof(tmp), %Y/%m/%d %X %A 本年第%j天 %z,localtime(&t) ); puts( tmp ); Staff p,*p1; int post,id; char Name20,ch; double pay,Amount,sell,programe; coutendl; coutendl; coutnnnnttt 添加职工信息endl; coutttt1-技术经理endl; coutttt2-业务经理endl; coutttt3-文 秘endl; coutttt4-业务人员endl; coutttt5-技术人员endl; coutttt6-财务人员endl;do fstream file(company.dat,ios:out|ios:app|ios:binary);/以写,追加,二进制形式打开文件 if(file.fail() coutcan not open file!endl; coutendlpost; coutid; coutName; switch(post) case 1:p1=new TechniqueManager(id,Name,post,0); /声明一个基类的指针指向派生类,用new创建了派生类的对象 pay=(*p1).Pay();p=TechniqueManager(id,Name,post,pay); break; case 2: coutsell; coutprograme; coutendl; p1=new BusinessManager(id,Name,post,sell,programe,0); pay=(*p1).Pay(); p=BusinessManager(id,Name,post,sell,programe,pay); break; case 3:p1=new Secretary(id,Name,post,0); pay=(*p1).Pay();p=Secretary(id,Name,post,pay); break; case 4:coutsell; coutprograme; coutendl; p1=new Sales(id,Name, post,sell,programe,0); pay=(*p1).Pay(); p=Sales(id,Name, post,sell,programe,pay);break; case 5: coutAmount; p1=new Technician(id,Name,post,Amount,0); pay=(*p1).Pay(); p=Technician(id,Name,post,Amount,pay);break; case 6:p1=new Financial(id,Name,post,0); pay=(*p1).Pay();p=Financial(id,Name,post,pay); break; file.write(char *)(&p),sizeof(p);/以写的方式读入文件中 file.close(); coutch;if(ch = n|ch = N)break;while(ch=y|ch=Y);system( cls); void Boss:Search() /查找员工信息 time_t t = time(0); char tmp64; strftime( tmp, sizeof(tmp), %Y/%m/%d %X %A 本年第%j天 %z,localtime(&t) ); puts( tmp ); int d; Staff p; char ch;coutnnnnnn 查找员工信息endl; coutttt1-技术经理endl;coutttt2-业务经理endl;coutttt3-文 秘endl;coutttt4-业务人员endl;coutttt5-技术人员endl;coutttt6-财务人员endl; docoutd;coutendl;fstream file(company.dat,ios:in|ios:binary);/以读的方式打开文件,if(file.fail() coutcan not open the file!endl; while(file.read(char *)&p,sizeof(p)/文件中的内容一个一个的读出来,不停止,直到文件尾 if(d=1&p.post=1) coutp.num 技术经理 p.incomeendl; else if(d=2&p.post=2) coutp.num 财务经理 p.incomeendl; else if(d=3&p.post=3) coutp.num 文 秘 p.incomeendl; else if(d=4&p.post=4) coutp.num 业务人员 p.incomeendl; else if(d=5&p.post=5) coutp.num 技术人员 p.incomeendl; else if(d=6&p.post=6) coutp.num 财务人员 p.incomeendl; file.close(); coutch;if(ch = n|ch = N)break;while(ch=y|ch=Y); system( cls);void Boss:Modify() /-修改信息- time_t t = time(0); char tmp64; strftime( tmp, sizeof(tmp), %Y/%m/%d %X %A 本年第%j天 %z,localtime(&t) ); puts( tmp ); char Name20; Staff p310; Staff *p1; Staff p; int post,id,i=0,j=0; double pay,Amount,sell,programe; coutnnnnnn 修改员工信息endl; coutttt1-技术经理endl; coutttt2-业务经理endl; coutttt3-文 秘endl; coutttt4-业务人员endl; coutttt5-技术人员endl; coutttt6-财务人员endl; coutid; fstream file(company.dat,ios:in|ios:binary); if(file.fail() coutcan not open the file!endl; file.seekg(0,ios:beg); /把文件指针放在文件的开始 while(file.read(char *)&p,sizeof(p) p3i=p; if(p3i.num=id) coutpost; coutName;coutendl; switch(post) case 1:p1=new TechniqueManager(id,Name,post,0); pay=(*p1).Pay();p3i=TechniqueManager(id,Name,post,pay); break; case 2:coutsell; coutprograme; coutendl; p1=new BusinessManager(id,Name, post,sell,programe,0); pay=(*p1).Pay(); p3i=BusinessManager(id,Name, post,sell,programe,pay); break; case 3:p1=new Secretary(id,Name,post,0);pay=(*p1).Pay();p3i=Secretary(id,Name,post,pay); break; case 4:coutsell; coutprograme; coutendl; p1=new Sales(id,Name, post,sell,programe,0); pay=(*p1).Pay(); p3i=Sales(id,Name, post,sell,programe,pay); break; case 5:coutAmount; coutendl; p1=new Technician(id,Name,post,Amount,0); pay=(*p1).Pay(); p3i=Technician(id,Name,post,Amount,pay); case 6:p1=new Financial(id,Name,post,0);pay=(*p1).Pay();p3i=Financial(id,Name,post,pay); break; i+; file.close(); ofstream file1(company.dat,ios:out|ios:binary); if(file1.fail() coutcan not open the file!endl; for(j=0;ji;j+) /把修改后的信息存入文件中 file1.write(char *)&p3j,sizeof(p3j); file1.close(); system( cls); void Boss:Delete() /-删除人员-time_t t = time(0); char tmp64; strftime( tmp, sizeof(tmp), %Y/%m/%d %X %A 本年第%j天 %z,localtime(&t) ); puts( tmp ); int num,i,j=0;Staff p110;Staff p;char ch; doi=0;cout 删除员工信息;coutnum;fstream file(company.dat,ios:in|ios:binary); /输入文件流类 if(file.fail() coutcan not open the file!endl; while(file.read(char *)&p,sizeof(p)if(p.num=num)switch(p.post) case 1: coutp.num 技术经理 p.incomeendl;break;case 2: coutp.num 财务经理 p.incomeendl;break; case 3: coutp.num 文 秘 p.incomeendl; break; case 4: coutp.num 业务人员 p.incomeendl;break;case 5: coutp.num 技术员 p.incomeendl;break; case 6: coutp.num 财务人员 p.incomeendl;break; else p1i=p;i+;file.close();fstream file1(company.dat,ios:out|ios:binary); /输出文件流类 if(file1.fail()coutcan not open the file!endl; for(j=0;ji;j+)file1.write(char *)&p1j,sizeof(p1j); file1.close(); coutch;if(ch = n|ch = N)break;while(ch=y|ch=Y);system( cls);void Boss:DisPlay() /-显示人员信息- Staff p;/P是职员类的对象 cout 编号 员工姓名 级别 工资 endl; fstream file(company.dat,ios:in|ios:out|ios:binary); if(file.fail() coutcan not open the file!endl; while(file.read(char *)(&p),sizeof(p) / cout 编号 姓名 岗位 工资 endl; switch(p.post) case 1:cout p.num setw(6) setw(6)技术经理 p.incomeendl;break;case 2:cout p.num setw(6) setw(6)业务经理 p.incomeendl; break; case 3:cout p.num setw(6) setw(6) 文秘 p.incomeendl; break; case 4:cout p.num setw(6) setw(6)业务人员 p.incomeendl; break; case 5:cout p.num setw(6) setw(6)技术人员 p.incomeendl; break; case 6:cout p.num setw(6) setw(6)财务人员 p.incomeendl; break; file.close();

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论