Create a program using C++. Write an Employee class as a base class that contain
ID: 3827271 • Letter: C
Question
Create a program using C++. Write an Employee class as a base class that contains firstname,lastname, and ID number. The Employee class should have constructor, mutator, and accessor. Then create two derived classes as follows: 1.)A salaried employee that has annual salary member field and an hourly employee that has hourly salary member field. 2.)These classes should have an appropriate constructors and mutator methods to store values in the fields and accessor methods to return the values in the fields. 3.)Each class should have a weekly salary function that calculates the weekly base salary for the employee. a. Hourly emp. - base of 40 hr per week b. Salaried emp. - base of annual salary /50.
Explanation / Answer
Class Employee
{
Public:
int Id;
string FName;
string LName;
public:
//constructors
Empolyee();
Employee(int , string , string );
//mutators
int setId(int );
string setFName(string );
string setLName(string );
//Accessors
void getId();
void getFName();
void getLName();
void calcualteWeeklySal();
};
Employee::Employee(int Id, string FName, string LName)
{
Employee:: Id = Id;
Employee:: FName = Fname;
Employee:: LName = LName;
}
Void Employee:: setId(int Id)
{
Employee::Id = Id;
}
Void Employee:: setFName (int FName)
{
Employee:: FName = FName;
}
Void Employee:: setLName (int LName)
{
Employee:: LName = LName;
}
int Employee:: getId()
{
return Id;
}
string Employee:: getFName ()
{
return FName;
}
string Employee:: getLName ()
{
return LName;
}
Class AnnualEmp : public Employee
{
Public:
int yearly_sal;
public:
AnnualEmp(int);
int setYearly_sal();
void getYearly_sal();
};
AnnualEmp::AnnualEmp(int yearly_sal)
{
AnnualEmp:: yearly_sal = yearly_sal;
}
Void AnnualEmp:: setYearly_sal(int yearly_sal)
{
yearly_sal = yearly_sal;
}
int AnnualEmp:: getYearly_sal()
{
return yearly_sal;
Class HourlyEmp : public Employee
{
Public:
int hourly_sal;
public:
HourlyEmp();
int setHourly_sal();
void getHourly_sal();
};
HourlyEmp:: HourlyEmp (int hourly_sal)
{
HourlyEmp:: hourly_sal = hourly_sal;
}
Void HourlyEmp:: setHourly_sal (int hourly_sal)
{
hourly_sal = hourly_sal;
}
int HourlyEmp:: getHourly_sal ()
{
return hourly_sal;
}
}
void calculateWeeklySal()
{
if ( TotalHours <= 40)
pay = hourly_Sal * TotalHours;
else
pay = (40.0 * hourly_Sal) + (TotalHours - 40) * (hourly_Sal * 1.5);
}
int main()
{
AnnualEmp ae;
HourlyEmp he;
Cout<<”enter hours”;
Cin>>TotalHour;
he.calcualteWeeklySal();
cout<<”enter id”;
cin>>Id;
cout<<”enter first name”;
cin>>FName;
cout<<”enter last name”;
cin>>LName;
}
if ( TotalHours <= 40)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.