In: Computer Science
Create an Employee class having the following functions and
print
the final salary in c++ program.
- getInfo; which takes the salary, number of hours of work per
day
of employee as parameters
- AddSal; which adds $10 to the salary of the employee if it is
less
than $500.
- AddWork; which adds $5 to the salary of the employee if the
number of hours of work per day is more than 6 hours.
Here is the Employee class in C++
=============================================================
class Employee{
private:
double hours;
double salary;
public:
void getInfo(double hrs, double
sal);
void print() const;
void AddSal();
void AddWork();
};
void Employee::getInfo(double hrs, double sal){
salary = sal;
hours =hrs;
}
void Employee::print() const{
cout<<"Employee Salary $"<<salary
<<", Hours:
"<<hours<<endl;
}
void Employee::AddSal(){
if(salary<500) salary+=10;
}
void Employee::AddWork(){
if(hours<6) salary += 5;
}
=============================================================
// BELOW IS THE COMPLETE C++ PROGRAM
#include<iostream>
#include<iomanip>
using namespace std;
class Employee{
private:
double hours;
double salary;
public:
void getInfo(double hrs, double
sal);
void print() const;
void AddSal();
void AddWork();
};
void Employee::getInfo(double hrs, double sal){
salary = sal;
hours =hrs;
}
void Employee::print() const{
cout<<"Employee Salary $"<<salary
<<", Hours:
"<<hours<<endl;
}
void Employee::AddSal(){
if(salary<500) salary+=10;
}
void Employee::AddWork(){
if(hours<6) salary += 5;
}
int main(){
Employee e;
e.getInfo(5,400);
e.print();
e.AddSal(); cout<<"Invoking AddSal()\n";
e.print();
e.AddWork();cout<<"Invoking AddWork()\n";
e.print();
return 0;
}
=============================================================