I am writing a C++ program about an Employee class about classes and multiple in
ID: 3764414 • Letter: I
Question
I am writing a C++ program about an Employee class about classes and multiple inheritances but I keep getting an error when I try to run it.
The error is displayed below
This is the code below:
#include<iostream>
#include<string>
#define FACULTY_MONTHLY_SALARY 5000.00
#define STAFF_MONTHLY_HOURS_WORKED 160
using namespace std;
class Date
{
public:
int d;
int m;
int y;
public:
Date()
{
d=1;
m=1;
y=2010;
}
Date(int d1,int m1,int y1)
{
d=d1;
m=m1;
y=y1;
}
Date(const Date &s)
{
d=s.d;
m=s.m;
y=s.y;
}
};
class Employee
{
private:
string lname;
string fname;
string ID;
char sex;
Date *Bdate;
public:
Employee()
{
lname=" ";
fname=" ";
ID="";
sex='F';
Bdate=new Date(1,1,2010);
}
Employee(const string& ln,const string& fn,const string& id,char s,Date m1)
{
lname=ln;
fname=fn;
ID=id;
sex=s;
Bdate=new Date(m1.d,m1.m,m1.y);
}
void setempfName(const string& f)
{
fname=f;
}
void getemplname(const string& l)
{
lname=l;
}
void getID(const string& id)
{
ID=id;
}
string getempfName()
{
return fname;
}
string getemplname()
{
return lname;
}
string getID()
{
return ID;
}
void putData() const
{
cout<<"Employee Name:"<<fname<<" "<<lname<<endl;
cout<<"Employee id:"<<ID<<endl;
cout<<"Sex:"<<sex<<endl;
cout<<"Birth Date:"<<Bdate->d<<"-"<<Bdate->m<<"-"<<Bdate->y<<endl;
}
virtual double monthlyEarning()=0;
};
class Staff:public Employee
{
double hourlyRate;
public:
Staff():Employee()
{
hourlyRate=1;
}
Staff(const string& l,const string& f,const string& id,char s,Date m,double rate):Employee(l,f,id,s,m)
{
setHourlyRate(1);
}
void setHourlyRate(double rate)
{
hourlyRate=rate;
}
double getHourlyRate()
{
return hourlyRate;
}
double monthlyEarning()
{
return hourlyRate*160;
}
void putData()
{
cout<<" STAFF INFORMATION:"<<endl;
Employee::putData();
cout<<" Monthly Earning:"<< monthlyEarning() <<endl;
}
};
class Education
{
string degree;
string major;
int research;
public:
Education()
{
degree="MS";
major="Engg";
research=1;
}
Education(const string& d,const string& m,int r)
{
degree=d;
major=m;
research=r;
}
void setDegree(const string& d)
{
degree=d;
}
string getDegree()const
{
return degree;
}
void setMajor(const string& m)
{
major=m;}
string getMajor()const
{
return major;
}
void setResearch(int r)
{
research=r;
}
int getResearch()
{
return research;
}
};
class Faculty:public Employee
{
string level;
Education *edu;
public:
Faculty():Employee()
{
level="AS";
edu=new Education();
}
Faculty(const string& l,const string& f,const string& id,char s,Date b,const string& lvl,Education e):Employee(l,f,id,s,b)
{
level=lvl;
edu= new Education(e.getDegree(), e.getMajor(), e.getResearch());
}
double monthlyEarning()
{
if(level=="AS")
return FACULTY_MONTHLY_SALARY;
else if(level=="AO")
return FACULTY_MONTHLY_SALARY*1.2;
else if(level=="FU")
return FACULTY_MONTHLY_SALARY*1.4;
return 0;
}
void putData()
{
cout<<"Faculty information:"<<endl;
Employee::putData();
cout<<level<<" professor"<<endl;
cout<<"Monthly Earning:"<<monthlyEarning()<<endl;
}
};
class Parttime:public Staff
{
int hoursWorked;
public:
Parttime(const string& l,const string& f,const string& id,char s,Date m,double rate,int wh):Staff(l,f,id,s,m,rate)
{
setHoursWorked(wh);
}
void setHoursWorked(int wh)
{
hoursWorked=wh;
}
double monthlyEarning()
{
double r;
r=Staff::getHourlyRate();
return r*hoursWorked*4;
}
void putData()
{
cout<<"PARTTIMESTAFF INFORMATION:"<<endl;
Staff::putData();
cout<<"HOURS WORKS PER MONTH:"<<hoursWorked*4<<endl;
cout<<"Monthly Earning:"<<monthlyEarning()<<endl;
}
};
int main()
{
Employee * ePtr[10];
Staff s1;
ePtr[0] = new Staff("John","jerry","12345",'F',new Date(1,12,1965),10);
Staff s2("jerry","K","11111",'M',new Date(1,5,1987),12);
e[0]=s1;
e[1]=s2;
Faculty f1("John","jerry","135",'F',new Date(1,2,1985),"AS",new Education("MS","Engineering",12));
Faculty f2("jai","k","122",'M',new Date(1,3,1995),"AO",new Education("MD","Engineering",8));
e[2]=f1;
e[3]=f2;
Parttime p1("w","charles","133",'M',new Date(1,8,1990),100,4);
Parttime p2("jai","k","155",'F',new Date(1,3,1981),120,6);
e[4]=p1;
e[5]=p2;
for(k1=0;k1<10;k1++)
{
e[k1].putData();
}
s1.putData();
s2.putData();
f1.putData();
f2.putData();
p1.putData();
p2.putData();
}
In function 'int mainO: [Error] no matching function for call to 'Staff:Staff const char [5], const char [6], const char [6], char, Date*, int) Note] candidates are: [Note] Staff: Staff(const string& const string& const string&, char, Date, double) [Note] no known conversion for argument 5 from 'Date to Date [Note] Staff:Staff0 [Note] candidate expects 0 arguments, 6 provided [Note] Staff::Staff(const Staff&) Note candidate expects 1 argument, 6 provided Error] no matching function for call to 'Staff: Staff(const char [6], const char [21, const char [6), char, Date*, int) [Note] candidates are: [Note] Staff:Staff(const string&,const string&,const string&, char, Date, double)Explanation / Answer
Code:
#include <iostream.h>
#include <string.h>
#include <conio.h>
class employee
{
char emp_name[10];
int workingdays;
int present;
public:
employee(int w,int p,char* name)
{
workingdays = w;
present = p;
strcpy(emp_name,name);
}
virtual void display() { }
};
class clerk : public employee
{
int rubberstamp;
int sal_rate;
public:
clerk(int w, int p,char *name) : employee(w,p,name)
{
rubberstamp = 1;
sal_rate = 100;
}
int salary1() { return present * sal_rate; }
void display();
};
class mgr : public employee
{
int supervi,sal_rate;
public:
mgr(int w, int p,char *name,int su) : employee(w,p,name)
{
supervi = su;
sal_rate = 1000;
}
int salary2() { return present * sal_rate; }
void display();
};
void clerk :: display()
{
cout<<" NAME : "<<emp_name;
cout<<" DAYS PRESENT : "<<present;
cout<<endl<<salary1();
}
void mgr :: display()
{
cout<<" NAME : "<<emp_name;
cout<<" DAYS PRESENT : "<<present;
cout<<supervi;
cout<<endl<<salary2();
}
void main()
{
clrscr();
clerk c(50,10,"john");
mgr m(40,10,"trump",20);
employee* e[2];
e[0]=&c;
e[1]=&m;
e[0]->display();
e[1]->display();
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.