公司的工资管理系统,但是有一处错误一直没找到

woshuo123mutouren 2009-06-22 06:19:42
编写一个小型公司的工资管理系统。该公司主要有4类人员:经理、兼职技术人员、销售员和销售经理。要求存储并显示每类人员的编号(从100起编号)、姓名和月薪,同时给出在创建每一类对象时构造函数的执行顺序(月薪计算方法为:经理固定月薪8000元,兼职技术人员100元/小时,销售员为当月销售额的4%,销售经理保底工资5000元另加其所管部门销售额的5%)。

代码中 有一处错误,一直没找到。高手门。解决下~~~~~大家一起分享~


#include "stdafx.h"
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
class Employee
{
public:
friend class worker;
void shanchu() {*name=*sex=0;number=age=0;}
Employee() {next=0;}
virtual void print()=0;
void input()
{
cout<<"员工号:"<<" "
<<"姓名:"<<" "
<<"性别:"<<" "
<<"年龄:"<<endl;
cin>>number>>name>>sex>>age;
}
protected:
int number,age;
char name[20],sex[10];
Employee *next;
};


class technician:virtual public Employee
{
public:
technician() {}
virtual void shanchu() {*name=*sex=0;number=age=hour=0;pay1=0;}
void wage() { pay1=100*hour;}
virtual void print()
{
wage();
cout<<"技术员员工号:"<<number<<" "
<<"姓名:"<<name<<" "
<<"性别:"<<sex<<" "
<<"年龄:"<<age<<" "
<<"工资:"<<pay1<<endl;
}
void input()
{
Employee::input();
cout<<"工作时间(以小时计算)"<<endl;
cin>>hour;
}
protected:
int hour,pay1;
};


class manager:virtual public Employee
{
public:
friend class SM;
manager() {}
virtual void shanchu() {*name=*sex=0;number=age=month=0;pay2=0;}
void wage() {pay2=800*month;}
virtual void print()
{
wage();
cout<<"经理的员工号:"<<number<<" "
<<"姓名:"<<name<<" "
<<"性别:"<<sex<<" "
<<"年龄:"<<age<<" "
<<"工资:"<<pay2<<endl;
}
void input()
{
Employee::input();
cout<<"工作时间(以月份计算)"<<endl;
cin>>month;
}
protected:
int month,pay2;
};


class seller:virtual Employee
{
public:
friend class SM;
seller() {}
virtual void shanchu()
{*name=*sex=0;number=age=0;salesvolume=pay3=0;}
void wage() {pay3=salesvolume*0.04;}
void input()
{
Employee::input();
cout<<"销售额为(以人民币计算)"<<endl;
cin>>salesvolume;
}
virtual void print()
{
pay3=salesvolume*0.04;
cout<<"销售员员工号:"<<number<<" "
<<"姓名:"<<name<<" "
<<"性别:"<<sex<<" "
<<"年龄:"<<age<<" "
<<"工资:"<<pay3<<endl;
}
protected:
double salesvolume, pay3;
};


class SM:public manager,public seller
{
public:
friend class worker;
SM() {}
virtual void shanchu() {*name=*sex=0;number=age=0;total=pay4=0;}
void wage()
{

pay4=5000+(total)*0.005;
}
void input()
{
Employee::input();
cout<<"销售总额为(以人民币计算):"<<endl; //要用get_sum()*/
cin>>total;
}
virtual void print()
{
wage();
cout<<"销售经理员工号:"<<number<<" "
<<"姓名:"<<name<<" "
<<"性别:"<<sex<<" "
<<"年龄:"<<age<<" "
<<"工资:"<<pay4<<endl;}
protected:
double total,pay4;
};


class worker
{
public:
technician *pa;
seller *pb;
manager *pc;
SM *pd;
Employee *p;
Employee *p1; /* int number,age,hour,month;salemoney;char *name,*sex; 重复定义*/
worker()
{
Employee *p=new technician;p1=p;
}
void add();
void output(); //不能用print() 二义性
void find();
void change();
void del(); //不能使用关键字delete
void save();
};

void worker::add()
{
int a;
Employee *p=p1;
while(p->next)
p=p->next;
cout<<"请选择您所想输入员工的岗位代码,再进行操作.谢谢合作!"<<endl;



作者:202.206.242.*2007-7-14 12:51 回复此发言

--------------------------------------------------------------------------------

17 回复:编写一个小型公司的工资管理系统
cout<<"1.技术员 2.销售员 3.经理 4.销售经理"<<endl;
cin>>a;
switch(a)
{
case 1:
cout<<"技术员数据:"<<endl;
pa=new technician;
pa->input();
p->next=pa;
break;
case 2:
cout<<"销售员数据:"<<endl;
pb=new seller;
pb->input();
p->next=pb;
break;
case 3:
cout<<"经理数据:"<<endl;
pc=new manager;
pc->input();
p->next=pc;
break;
case 4:
cout<<"销售经理数据:"<<endl;
pd=new SM;
pd->input();
p->next=pd;
break;
default:
cout<<"对不起!你所选的操作错误,请重新做作!"<<endl;
}

}

void worker::output()
{
Employee *p=p1->next;
if(!p)
{
cout<<"无职工记录或者记录已清除!"<<endl;
return;
}
while(p)
{
p->print();
p=p->next;
}
}

void worker::find()
{
Employee *p=p1->next;
if(!p)
{
cout<<"无职工记录或者记录已清除!"<<endl;
return;
}
cout<<"请输入该员工的员工号:"<<endl;
int b;
cin>>b;
for(p;p=p->next;)
{
if(p->number==b)
{
cout<<"您好,该员工已找到."<<endl;
p->print();
break;
}
}
if(!p)
{
cout<<"对不起!无该员工数据,请重新操作."<<endl;
}
}

void worker::change()
{
Employee *p=p1->next;
if(!p)
{
cout<<"无职工记录或者记录已清除!"<<endl;
return;
}
cout<<"请输入该员工的员工号:"<<endl;
int c;
cin>>c;
for(p;p=p->next;)
{
if(p->number==c)
{
cout<<"该员工的原数据是"<<endl;
p->print();
cout<<"请输入你想修改的数据"<<endl;
p->input();
cout<<"恭喜您,修改成功!"<<endl;
break;
}
}
if(!p)
{
cout<<"对不起!无该员工数据,请重新操作."<<endl;
}
}

void worker::del()
{
Employee *p=p1->next;
if(!p)
{
cout<<"无职工记录或者记录已清除!"<<endl;
return;
}
cout<<"请输入该员工的员工号:"<<endl;
int d;
cin>>d;
for(p;p=p->next;)
{
if(p->number==d)
{
cout<<"您好,删除成功!"<<endl;
p->shanchu();
break;
}
}
if(!p)
{
cout<<"对不起!无该员工数据,请重新操作."<<endl;
}
}

void worker::save()
{
char sh;
ifstream f1("F:\\ccx1.cpp");
if(!f1)
{
cout<<"cannot openf1for input";
abort();
}
ofstream f2("F:\\ccx.cpp");
if(!f2)
{
cout<<"cannot open f2 output";
abort();
}
while(f1.get(sh))
f2.put(sh);
f1.close();
f2.close();
cout<<"您好,您的数据已成功备份在F盘ccx.cpp文件中"<<endl;
}


void main()
{
cout<<"请输入密码(plaese input the pass word):"<<endl;
int e;
cin>>e;
if(e==19881001)
{
cout<<" ********欢迎进入本公司工资管理系统****** "<<endl;
worker w;
int f=1;
while(f)
{
cout<<"以下是菜单选项,请选择!"<<endl;
cout<<"1.输入成员数据"<<endl;
cout<<"2.输出成员数据"<<endl;
cout<<"3.查找成员数据"<<endl;
cout<<"4.修改成员数据"<<endl;
cout<<"5.删除成员数据"<<endl;
cout<<"6.清屏成员数据"<<endl;
cout<<"7.备份成员数据"<<endl;
cout<<"8.退出程序"<<endl;
int g;
cin>>g;
switch(g)
{
case 1:
w.add();
break;
case 2:
w.output();
break;
case 3:
w.find();
break;
case 4:
w.change();
break;
case 5:
w.del();
break;
case 6:
system("cls");
break;
case 7:
w.save();
break;
case 8:
abort();
default:
cout<<"对不起!你所选的操作错误,请重新做作!"<<endl;
}
}
}
else
{
cout<<"密码错误,系统将自动关闭!"<<endl;
abort();
}
}


...全文
123 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
大海啊全是水 2009-07-06
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 The_facE 的回复:]
这个世界太疯狂了。
[/Quote]

确实很疯狂
The_facE 2009-07-06
  • 打赏
  • 举报
回复
这个世界太疯狂了。
ysysbaobei 2009-07-06
  • 打赏
  • 举报
回复
顶一下
chang_an_liu 2009-07-06
  • 打赏
  • 举报
回复
像是学生写作业呀,还是自己一步一步搞清楚比较好,不是什么都要问人的
Wolf0403 2009-07-06
  • 打赏
  • 举报
回复
楼主,还是自己学着写一个吧。
TIMXG 2009-07-05
  • 打赏
  • 举报
回复
还有不知道怎么对 对象存文件
TIMXG 2009-07-05
  • 打赏
  • 举报
回复
我仿照C++ 大学教程上面写的一个,就是不知道怎么样对 对象来进行查找,删除,添加,呵呵
//EMPLOYEE.H
class Employee
{
public:
Employee(int, const char*,const char*,const char*,int);
~Employee();

void setEmployeeNumber(int);
void setEmployeeAge(int);

int getEmployeeNumber() const;
int getEmployeeAge() const;
const char* getFirstName() const;
const char* getLastName() const;
const char* getEmployeeSex() const;

virtual double earnings() const = 0;
virtual void print();
private:
int EmployeeNumber;
char* firstName;
char* lastName;
char* EmployeeSex;
int EmployeeAge;
};

//EMPLOYEE.CPP
#include"employee.h"
#include"string.h"
#include"assert.h"
#include<iostream.h>

Employee::Employee(int employNum,const char* first,const char* last,const char* sex,int age)
{
setEmployeeNumber(employNum);

firstName = new char[strlen(first) + 1];
assert(firstName != 0);
strcpy(firstName,first);

lastName = new char[strlen(last) + 1];
assert(lastName != 0);
strcpy(lastName,last);

EmployeeSex = new char[strlen(sex) + 1];
assert(EmployeeSex != 0);
strcpy(EmployeeSex,sex);

setEmployeeAge(age);
}

Employee::~Employee()
{
delete[] firstName;
delete[] lastName;
delete[] EmployeeSex;
}

void Employee::setEmployeeAge(int age)
{
EmployeeAge = age;
}

void Employee::setEmployeeNumber(int number)
{
EmployeeNumber = number;
}

const char* Employee::getFirstName() const
{
return firstName;
}

const char* Employee::getLastName() const
{
return lastName;
}

const char* Employee::getEmployeeSex() const
{
return EmployeeSex;
}

int Employee::getEmployeeAge() const { return EmployeeAge;}
int Employee::getEmployeeNumber() const { return EmployeeNumber;}

void Employee::print()
{
cout <<EmployeeNumber << ' ' << firstName << ' ' << lastName << ' ' << EmployeeSex << ' '<< EmployeeAge;
}

//BOSS.H
#include"employee.h"
class Boss : public Employee
{
public:
Boss(int,const char*,const char*,const char*,int,double);
void setMonthSalary(double);
virtual double earnings() const;
virtual void print() ;
private:
double manageMonthSalary;
};


//BOSS.CPP
#include<iostream.h>
#include<string.h>
#include"boss.h"

Boss::Boss(int number,const char* first,const char* last,const char* sex,int age,double monthSalary)
: Employee(number,first,last,sex,age)
{
setMonthSalary(monthSalary);
}

void Boss::setMonthSalary(double monthsalary)
{
manageMonthSalary = monthsalary;
}

double Boss::earnings() const
{
return manageMonthSalary;
}

void Boss::print()
{
cout << "\n Boss:";
Employee::print();
}

//COMMISSION.H
#include"employee.h"
class CommissionWor : public Employee
{
public:
CommissionWor(int,const char*,const char*,const char*,int,double,double,double);
void setSalary(double);
void setCommission(double );
void setQuantity(double);
virtual double earnings();
virtual void print();
private:
double Saraly;
double Commission;
double Quantity;
};

//COMMISSION.CPP
#include"commission.h"
#include<string.h>
#include<assert.h>
#include<iostream.h>
CommissionWor::CommissionWor(int number,const char* first,const char* last,const char* sex,int age,double comSaraly,double commiss,double quti)
: Employee(number,first,last,sex,age)
{
setCommission(commiss);
setQuantity(quti);
setSalary(comSaraly);
}

void CommissionWor::setCommission(double com)
{
Commission = com;
}

void CommissionWor::setQuantity(double qu)
{
Quantity = qu;
}

void CommissionWor::setSalary(double sa)
{
Saraly = sa;
}

double CommissionWor::earnings()
{
return Saraly + Commission * Quantity;
}

void CommissionWor::print()
{
cout << "\n CommissionWor";
Employee::print();
}

//HOURLYWORKER.H
#include"employee.h"
class HourlyWorker : public Employee
{
public:
HourlyWorker(int ,const char*,const char*,const char*,int ,double,double);
void setHour(double);
void setHourPay(double);
virtual void print();
virtual double earnings();
private:
double workHour;
double hourPay;
};


//HOURLYWORKER.CPP
#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<iostream.h>
#include"hourlyworker.h"


HourlyWorker::HourlyWorker(int number,const char* first,const char* last,const char* sex,int age,double hour, double hourPay)
: Employee(number,first,last,sex,age)
{
setHour(hour);
setHourPay(hourPay);
}

void HourlyWorker::setHour(double h)
{
workHour = h;
}

void HourlyWorker::setHourPay(double hourP)
{
hourPay = hourP;
}

void HourlyWorker::print()
{
cout << "\n HourlyWorker";
Employee::print();
}

double HourlyWorker::earnings()
{
return hourPay * workHour;
}

//PIECEWORKER.H
#include"employee.h"
class PieceWork : public Employee
{
public:
PieceWork::PieceWork(int ,const char* ,const char*,const char*,int,int,double);
void setWagePerPiece(double);
void setQuantity(int);
virtual double earnings();
virtual void print();
private:
int quantity;
double wagePerPiece;
};

//PIECEWORKER.CPP
#include"pieceworker.h"
#include<string.h>
#include<assert.h>
#include<iostream.h>
PieceWork::PieceWork(int number,const char* first,const char* last,const char* sex,int age,int quan,double wagePerP)
:Employee(number,first,last,sex,age)
{
setQuantity(quan);
setWagePerPiece(wagePerP);
}

void PieceWork::setQuantity(int q)
{
quantity = q;
}

void PieceWork::setWagePerPiece(double w)
{
wagePerPiece = w;
}

double PieceWork::earnings()
{
return quantity * wagePerPiece;
}

void PieceWork::print()
{
cout << "\n PieceWork:";
Employee::print();
}

//SALARYMA.CPP
#include<iostream.h>
#include<iomanip.h>
#include"boss.h"


void main()
{
cout << setiosflags(ios::fixed | ios::showpoint )
<< setprecision(2);
Boss b(100,"Join","Smith","man",30,3000);
b.print();
cout << "earning" << b.earnings() << "\n";
}

robin97 2009-07-03
  • 打赏
  • 举报
回复
编写一个小型公司的工资管理系统。
=============================================

练习就练习,不要说是公司的,现在还有公司在用字符界面的工资管理系统?
vcchen_bo_qiang 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 vcchen_bo_qiang 的回复:]
把头文件#include "stdafx.h" 改为#include "stdio.h" 就可以啦!!
[/Quote]

错啦!!不好意思!!应该不要头文件#include "stdafx.h"
zucc_bug 2009-07-01
  • 打赏
  • 举报
回复
真叫一个汗啊。。对LZ没想法了。。。。
vcchen_bo_qiang 2009-06-25
  • 打赏
  • 举报
回复
“<<” 和“>>”
输入输出运算符中间没有空格的 !!
vcchen_bo_qiang 2009-06-25
  • 打赏
  • 举报
回复
把头文件#include "stdafx.h" 改为#include "stdio.h" 就可以啦!!
K_s_G 2009-06-24
  • 打赏
  • 举报
回复
up[Quote=引用 11 楼 Darkneece 的回复:]
显然是论坛的代码直接复制过去了
[/Quote]
Darkneece 2009-06-24
  • 打赏
  • 举报
回复
显然是论坛的代码直接复制过去了
FengRider 2009-06-23
  • 打赏
  • 举报
回复
代码我试了一下,确实有些问题。修作修改,比如将cout < <改成cout<< , 再就是将#include<fstream.h>改为#include<fstream>,增加using namespace std;之后,至少还是能够出现登陆的界面部分。但实际使用的时候,各功能模块还是存在一些问题,譬如增加员工失败,备份抛异常等,实在是没兴趣再整下去。楼主自己再好好研究一下吧。一些简单的逻辑上面的错误,很可能只是一时手误引起的。
liuxin159357 2009-06-23
  • 打赏
  • 举报
回复
..................
赵文波 2009-06-23
  • 打赏
  • 举报
回复
#include "stdafx.h" \\这一行不要了

在最后一个#include的后面加一行 using namespace std:
应该就可以了。
itegel84 2009-06-23
  • 打赏
  • 举报
回复
CSDN最牛帖
  • 打赏
  • 举报
回复
很长,帮顶。
如果< < 你没有改成<<,我也服了你。
goodname 2009-06-22
  • 打赏
  • 举报
回复
<<中间的空格都要去掉,看来这c++你是一点也不会。
加载更多回复(4)

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧