我必须将此程序编写为作业。我已经结构出现以下错误一周了。谢谢。
1. x,w,y is undefined.
2. For checkin/checkout it says "declaration is in compatible with void employee::checkin/checkout(int,int,int)"
3. In this->Time(a,b,c) it's said type name is not allowed.
P.S。如果无论如何要改进它或需要修理的东西请告诉我那将是非常好的。再次感谢。
#include <iostream>
#include <iomanip>
#define N 2
using namespace std;
class Time
{
private:int h,m,s;
public:
void time_diff(Time T1,Time T2)
{
Time t;
t.s=(60+T2.s-T1.s)%60;
t.m=(60+T2.m-T1.m+(1-(60+T2.s-T1.s)/60))%60;
t.h=T2.h-T1.h+(1-(60+T2.m-T1.m+(1-(60+T2.s-T1.s)/60))/60);
t.h=t.h<0?t.h+=24:t.h;
*this=t;
}
Time(int hh=0,int mm=0,int ss=0){
s=ss%60;
m=(mm+ss/60)%60;
h=(hh+(mm+ss/60)/60)%24;
}
void set_time(int a,int b,int c){
this->Time(a,b,c);
}
double converter(int hn,int m,int s)
{
int hn,mn,sn;
hn=h*3600;
mn=m*60;
sn=hn+mn+s;
return sn;
}
};
class employee
{
int id;
protected:
Time t_in,t_out;
double wage;
public:
employee(int=0,double=5);
void checkin(int,int,int);//set t_in
void checkout(int,int,int);//set t_out
void display();//display id and total time at work (t_out-t_in )
};
employee::employee(int w,double x)
{
x=wage;
w=id;
}
class staff:public employee{
public:
double get_paid();//wage*(t_out-t_in);
staff(int=0,int=5);//id,wage
};
void employee::checkin()
{
t_in.set_time(x,w,y);
}
void employee::checkout()
{
t_out.set_time(x,w,y);
}
double staff::get_paid()
{
int paid,load;
Time wo;
wo.time_diff(t_out,t_in);
load=wo.converter;
paid=load*wage;
}
答案 0 :(得分:0)
如果你真的需要set_time,试试这个::
class Time
{
...
void set_time(int a, int b, int c) {
*this = new Time(a, b, c);
}
...
}
...但是我觉得set_time没用,因为你已经有了构造函数。
在签入/结账时,您必须重复声明的同一公司,所以:
void employee::checkin(int x, int w, int y)
{
t_in.set_time(x, w, y);
}
void employee::checkout(int x, int w, int y)
{
t_out.set_time(x, w, y);
}
确实构造函数员工是错误的,因为您使用成员字段salary和id的相同值设置本地参数x和w,但这些值为零并保持不变。 你可能会喜欢反过来,所以:
employee::employee(int w, double x)
{
wage = x;
id = w;
}