- max笔记
-
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
//employee.h
class employee
{
protected:
char name[20]; //姓名
int individualEmpNo; //个人编号
int grade ; //级别
double accumPay; //月薪总额
int tag;
static int employeeNo; //本公司职员编号目前最大值
public:
employee(); //构造函数
~employee(); //析构函数
virtual void pay(); //计算月薪函数(虚函数)
virtual void promote(int increment=0); //升级函数(虚函数)
void SetName(char *); //设置姓名函数
char * GetName(); //提取姓名函数
int GetindividualEmpNo(); //提取编号函数
int Getgrade(); //提取级别函数
double GetaccumPay(); //提取月薪函数
void Tg();
int Gettag();
void add(char *na,int code,int gr,double p);
};
class technician:public employee //兼职技术人员
{
private:
double hourlyRate; //每小时酬金
int workHours; //当月工作时数
public:
technician(); //构造函数
void SetworkHours(int wh); //设置工作时数函数
void pay(); //计算月薪函数
void promote(int); //升级函数
};
class salesman: virtual public employee //兼职推销人员类
{
protected:
double CommRate; //按销售额提取酬金的百分比
double sales; //当月销售额
public:
salesman(); //构造函数
void Setsales(double s1); //设置销售额函数
void pay(); //计算月薪函数
void promote(int); //升级函数
};
class manager:virtual public employee //经理类
{
protected:
double monthlyPay;
public:
manager(); //构造函数
void pay(); //计算月薪函数
void promote(int); //升级函数
};
class salesmanager:public manager,public salesman //销售经理
{
public:
salesmanager(); //构造函数
void pay(); //计算月薪函数
void promote(int); //升级函数
};
class Database//职工数据类
{
private:
int top;
employee read[100];
public:
Database();//将职工信息从employee.txt读取到read[]中
int addemp (char *na,int code,int gr,double p) ;//增加职工
employee *query(int empid) ;
employee *query1(char empna[20]) ;
void disp() ;//职工信息显示
void clear();
~Database(); //将read[]中的信息读如到employee.txt中
};
#endif
//employee.cpp
#include <iostream>
#include <cstring>
#include "employee.h"
#include <fstream>
using namespace std;
int employee::employeeNo=1000; //员工编号基数为1000
//成员函数的类外定义
employee::employee()
{
individualEmpNo=employeeNo++; //新输入的员工编号为目前最大编号加1
grade=1; //级别初值为1
accumPay=0.0; //月薪总额初值为0
}
void employee::add(char *na,int code,int gr,double pay)
{
tag=0;
SetName(na);individualEmpNo=code;grade=gr;accumPay=pay;
}
void employee::pay(){};
employee::~employee()
{}
void employee::promote(int increment)
{ grade+=increment;} //升级,提升的级数由increment指定
void employee::SetName(char * names)
{ strcpy(name,names);} //设置姓名
char * employee::GetName()
{return name;} //提取成员姓名
int employee::GetindividualEmpNo()
{return individualEmpNo;}
int employee::Getgrade()
{ return grade;} //提取成员级别
double employee::GetaccumPay()
{ return accumPay;} //提取月薪
technician::technician()
{ hourlyRate=100;} //每小时酬金100
void technician::SetworkHours(int wh)
{ workHours=wh;} //设置工作时间
void technician::pay()
{ accumPay=hourlyRate*(double)workHours;} //计算月薪,按小时计酬
void technician::promote(int)
{ employee::promote(2);} //调用基类升级函数,升2级
salesman::salesman()
{ CommRate=0.04;} //销售提成比例4%
void salesman::Setsales(double s1)
{ sales=s1;} //设置销售额
void salesman::pay()
{ accumPay=sales*CommRate;} //月薪=销售提成
void salesman::promote(int)
{ employee::promote(0); } //调用基类升级函数,升0级
manager::manager()
{ monthlyPay=8000;} //固定月薪8000元
void manager::pay()
{ accumPay=monthlyPay;} //月薪总额即固定月薪数
void manager::promote(int)
{ employee::promote(3);} //调用基类升级函数,升3级
salesmanager::salesmanager()
{
monthlyPay=5000;
CommRate=0.005;
}
void salesmanager::pay()
{
accumPay=(double)monthlyPay+CommRate*sales;
}
void salesmanager::promote(int)
{ employee::promote(1);} //调用基类升级函数,升1级
int employee::Gettag()
{return tag;}
void employee::Tg()
{
tag=1;
}
Database::Database()//将职工信息从employee.txt读取到read[]中
{
employee s;
top=-1;
fstream file("employee.txt",ios::in);
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file) break;
top++;
read[top]=s;
}
file.close();
}
int Database::addemp (char *na,int code,int gr,double p) //增加职工
{
employee *emp=query1(na);
if(emp==NULL)
{
top++;
read[top].add(na,code,gr,p);
return 1;
}return 0;
}
employee *Database:: query(int empid)
{
for (int i=0;i<=top;i++)
if (read[i].GetindividualEmpNo()==empid && read[i].Gettag()==0)
return &read[i];
return NULL;
}
employee *Database::query1(char empna[20])
{
for (int i=0;i<=top;i++)
if (strcmp(read[i].GetName(),empna)==0 && read[i].Gettag()==0)
return &read[i];
return NULL;
}
void Database::disp() //职工信息显示
{
for (int i=0;i<=top;i++)
{
cout<<"姓名:"<<read[i].GetName()<<" 编号:"<<read[i].GetindividualEmpNo()<<" 级别:"<<read[i].Getgrade();
if(read[i].Getgrade()==1) cout<<" 职务:"<<"销售员 ";
else if(read[i].Getgrade()==2) cout<<" 职务:"<<"销售经理 ";
else if(read[i].Getgrade()==3) cout<<" 职务:"<<"兼职技术人员 ";
else cout<<" 职务:"<<"经理 ";
cout<<"工资:"<<read[i].GetaccumPay()<<endl;
}
}
void Database::clear()
{top=-1;
}
Database::~Database() //将read[]中的信息读如到employee.txt中
{
fstream file("employee.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].Gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();
}
//rygl.cpp
#include <iostream.h>
#include <cstring>
#include "employee.h"
#include <fstream>
void main()
{
manager m;
technician t;
salesmanager sm;
salesman s;
char names[20],key[20];
int code,wh;
double am;
employee *emp;
Database data;
int i,k,j=0,kk=3;
while(kk)
{
cout<<"请输入密码(您还有"<<kk<<"次机会):";
cin>>key;kk--;
if(strcmp(key,"sm0903410")==0)break;
else cout<<"o(︶︿︶)o唉,密码错误!"<<endl;
if(kk==0) {cout<<"您已经不能再进入此系统!( ^_^ )/~~拜拜";exit(0);}
}
do{ 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<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"请选择您的操作:";cin>>i;
switch(i)
{
case 1:data.clear();
do{ system("cls");
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 1.经理 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 2.兼职技术人员 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 3.销售经理 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 4.兼职推销 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 5.返回上一级菜单 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"请选择您的操作:";cin>>k;
switch(k)
{
case 1:cout<<"请输入名字:";cin>>names;m.SetName(names);m.promote(0);m.pay();data.addemp(m.GetName(),m.GetindividualEmpNo(),m.Getgrade(),m.GetaccumPay());break;
case 2:cout<<"请输入名字:";cin>>names;cout<<"请输入他本月的工作时长:";cin>>wh;t.SetworkHours(wh);t.SetName(names);t.promote(0);t.pay();data.addemp(t.GetName(),t.GetindividualEmpNo(),t.Getgrade(),t.GetaccumPay());break;
case 3:cout<<"请输入名字:";cin>>names;cout<<"请输入他所管辖部门本月的销售总额:";cin>>am;sm.Setsales(am);sm.SetName(names);sm.promote(0);sm.pay();data.addemp(sm.GetName(),sm.GetindividualEmpNo(),sm.Getgrade(),sm.GetaccumPay());break;
case 4:cout<<"请输入名字:";cin>>names;cout<<"请输入他本月的销售总额:";cin>>am;s.Setsales(am);s.SetName(names);s.promote(0);s.pay();data.addemp(s.GetName(),s.GetindividualEmpNo(),s.Getgrade(),s.GetaccumPay());break;
default:cout<<"~~o(>_<)o~~ WRONG!"<<endl;break;
case 5:break;
}
}while(k!=5);break;
case 2:
do{ system("cls");
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 1.经理 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 2.兼职技术人员 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 3.销售经理 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 4.兼职推销 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 5.返回上一级菜单 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"请选择您要增加的类型:";cin>>k;
switch(k)
{
case 1:cout<<"请输入名字:";cin>>names;m.SetName(names);m.promote(0);m.pay();data.addemp(m.GetName(),m.GetindividualEmpNo(),m.Getgrade(),m.GetaccumPay());break;
case 2:cout<<"请输入名字:";cin>>names;cout<<"请输入他本月的工作时长:";cin>>wh;t.SetworkHours(wh);t.SetName(names);t.promote(0);t.pay();data.addemp(t.GetName(),t.GetindividualEmpNo(),t.Getgrade(),t.GetaccumPay());break;
case 3:cout<<"请输入名字:";cin>>names;cout<<"请输入他所管辖部门本月的销售总额:";cin>>am;sm.Setsales(am);sm.SetName(names);sm.promote(0);sm.pay();data.addemp(sm.GetName(),sm.GetindividualEmpNo(),sm.Getgrade(),sm.GetaccumPay());break;
case 4:cout<<"请输入名字:";cin>>names;cout<<"请输入他本月的销售总额:";cin>>am;s.Setsales(am);s.SetName(names);s.promote(0);s.pay();data.addemp(s.GetName(),s.GetindividualEmpNo(),s.Getgrade(),s.GetaccumPay());break;
case 5:break;
default:cout<<"~~o(>_<)o~~ WRONG!"<<endl;break;
}
}while(k!=5);break;
case 3:
do{
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 1.姓名 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 2.编号 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 3返回上一级菜单 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"请选择您的查找方式:";cin>>k;
switch(k)
{
case 1:cout<<"请输入您要查找的姓名:";cin>>names;
emp=data.query1(names);
if(emp==NULL) {cout<<"~~o(>_<)o~~ 查无此人"<<endl;break;}
else cout<<"姓名:"<<emp->GetName()<<"编号:"<<emp->GetindividualEmpNo()<<"级别:"<<emp->Getgrade()<<"工资:"<<emp->GetaccumPay()<<endl;;break;
case 2:cout<<"请输入您要查找的编号:";cin>>code;
emp=data.query(code);
if(emp==NULL) {cout<<"~~o(>_<)o~~ 查无此人"<<endl;break;}
else cout<<"姓名:"<<emp->GetName()<<"编号:"<<emp->GetindividualEmpNo()<<"级别:"<<emp->Getgrade()<<"工资:"<<emp->GetaccumPay()<<endl;;break;
case 3:break;
default:cout<<"~~o(>_<)o~~ WRONG!"<<endl;break;
}
}while(k!=3); break;
case 4:
do{ system("cls");
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 1.姓名 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 2.编号 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*! 3返回上一级菜单 !*!*!*!*!*!"<<endl;
cout<<"!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!"<<endl;
cout<<"请选择您的删除方式:";cin>>k;
switch(k)
{
case 1:cout<<"请输入您要删除的姓名:";cin>>names;
emp=data.query1(names);
if(emp==NULL) {cout<<"~~o(>_<)o~~ 查无此人"<<endl;break;}
emp->Tg();break;
case 2:cout<<"请输入您要删除的编号:";cin>>code;
emp=data.query(code);
if(emp==NULL) {cout<<"~~o(>_<)o~~ 查无此人"<<endl;break;}
emp->Tg();
break;
case 3:break;
default:cout<<"~~o(>_<)o~~ WRONG!"<<endl;break;
}
}while(k!=3);break;
case 5:data.disp();system("PAUSE");break;
case 6:cout<<"( ^_^ )/~~拜拜"<<endl;break;
default:cout<<"~~o(>_<)o~~ WRONG!"<<endl;break;
}
}while(i!=6);
}
和你那个类似的,我们去年的课设,你改改就好了
- wpBeta
-
#include <iostream>
#include<fstream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
int hexchar2int(char* str)
{
int i;
int multii = 1;
int ret = 0;
int len = strlen(str);
for(i=0;i<len;i++)
{
if(str[len-i-1] <= "9" &&str[len-i-1] >= "0" )
ret += (str[len-i-1]-"0")*multii;
else if(str[len-i-1] <= "z" &&str[len-i-1] >= "a" )
ret += (str[len-i-1]-"a" + 10)*multii;
else if(str[len-i-1] <= "Z" &&str[len-i-1] >= "A" )
ret += (str[len-i-1]-"A" + 10)*multii;
else
return -1;
multii*=16;
}
return ret;
}
int main()
{
char str1[10] = "10";
char str2[10] = "dc";
char str3[10] = "ffff";
char str4[10] = "32";
char str5[10] = "5";
cout<<"0x"<<str1 <<" = " << hexchar2int(str1) <<endl;
cout<<"0x"<<str2 <<" = " << hexchar2int(str2) <<endl;
cout<<"0x"<<str3 <<" = " << hexchar2int(str3) <<endl;
cout<<"0x"<<str4 <<" = " << hexchar2int(str4) <<endl;
cout<<"0x"<<str5 <<" = " << hexchar2int(str5) <<endl;
}
- LocCloud
-
分都不给......