Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSCI 225 Lab 1 Due: Friday, Week 2, Submit to: Ifs21csci-2251 lab1 Objectives: S

ID: 3875202 • Letter: C

Question

CSCI 225 Lab 1 Due: Friday, Week 2, Submit to: Ifs21csci-2251 lab1 Objectives: Starting point: from one of the last Labs in CSCI 125) Classes and class members Private data fields .Constructors, destructors Public methods Review: Use of #ifndef, #define, and #endif preprocessor directives Use of initializers .Use of typedef Inheritance Program over multiple source files Define and use ADT interface (virtual, template) Set up 1) Create a new folder under your drive, e.g., z:csci225lab1_yourNamel 2) Create a new VC++ solution named Lab1 Lab Tasks: Implement a class Employee (pay be hours): An Employee has a name, a hourly pay rate. a total income .Supply an appropriate constructor to set name and pay rate Supply functions get_name(), add_pay(int hours), get total_income(), and get_average_pay). To compute the average, you also need to store the number of pays that the employee earned. C++ solutions employeelnterface.h employee.h: employee.cpp ADT definition (bonus) declarations of the class Employee implementations of the class Employee main() that contains test cases to use the Employee class in employee.h . myLab1.cpp

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

employee.h
=========

#ifndef employee_h
#define employee_h
#include <iostream>
using std::string;
class Employee
{
private:
string name;
double hourly_rate;
int number_of_pays;
int hours_worked;
public:
Employee(string name1, double rate1); //constructor
string get_name();
void add_pay(int hours);
double get_total_income();
double get_average_pay();
double get_hourly_rate();
int get_hours_worked();
};
#endif /* employee_h */




employee.cpp
=========

#include "employee.h"
Employee::Employee(string name1, double rate1) //constructor
{
name = name1;
hourly_rate = rate1;
number_of_pays = 0;
hours_worked = 0;
}
string Employee::get_name()
{
return name;
}
void Employee::add_pay(int hours)
{
hours_worked += hours;
number_of_pays++;
}
double Employee::get_total_income()
{
return hours_worked * hourly_rate;
}
double Employee::get_average_pay()
{
if(number_of_pays == 0)
return 0;
else
return get_total_income() / number_of_pays;
}
double Employee::get_hourly_rate()
{
return hourly_rate;
}
int Employee::get_hours_worked()
{
return hours_worked;
}




myLab1.cpp
=======
#include <iostream>
#include "employee.h"
using namespace std;
int main()
{
Employee e1("John", 15);
  
cout << "Created employee John with hourly rate of 15" << endl;
cout << "Name: " << e1.get_name() << " Hours: " << e1.get_hours_worked()
<< " Rate: $" << e1.get_hourly_rate() << " Total: $" << e1.get_total_income() <<
" Average: $" << e1.get_average_pay() << endl << endl;
  
  
cout << "Adding 20 hours" << endl;
e1.add_pay(20);
cout << "Name: " << e1.get_name() << " Hours: " << e1.get_hours_worked()
<< " Rate: $" << e1.get_hourly_rate() << " Total: $" << e1.get_total_income() <<
" Average: $" << e1.get_average_pay() << endl << endl;
  
  
cout << "Adding 35 hours" << endl;
e1.add_pay(35);
cout << "Name: " << e1.get_name() << " Hours: " << e1.get_hours_worked()
<< " Rate: $" << e1.get_hourly_rate() << " Total: $" << e1.get_total_income() <<
" Average: $" << e1.get_average_pay() << endl << endl;
  
  
  
cout << "Adding 40 hours" << endl;
e1.add_pay(40);
cout << "Name: " << e1.get_name() << " Hours: " << e1.get_hours_worked()
<< " Rate: $" << e1.get_hourly_rate() << " Total: $" << e1.get_total_income() <<
" Average: $" << e1.get_average_pay() << endl << endl;
  
cout << "Good bye!" << endl;
return 0;
}




output
=====
Created employee John with hourly rate of 15
Name: John Hours: 0 Rate: $15 Total: $0 Average: $0
Adding 20 hours
Name: John Hours: 20 Rate: $15 Total: $300 Average: $300
Adding 35 hours
Name: John Hours: 55 Rate: $15 Total: $825 Average: $412.5
Adding 40 hours
Name: John Hours: 95 Rate: $15 Total: $1425 Average: $475
Good bye!