Question: Part 3 : Friend Function Consider the following Employee class: / / Employee . h class Employee { private: string name; double salary; public: Employee
Part : Friend Function
Consider the following Employee class:
Employeeh
class Employee
private:
string name;
double salary;
public:
Employeestring n double s;
string getName;
double getSalary;
friend bool operatorEmployee& Employee&;
friend void operatorEmployee& e Employee& e;
;
bool operatorEmployee& e Employee& e
return ename ename;
void operatorEmployee& e Employee& e
esalary esalary;
maincpp
#include Employeeh
int main
Employee eBob;
Employee eBill;
cout e e endl;
e e;
cout egetSalary egetSalary endl;
return ;
Compile and run the programs.
Your Turn:
pts Declare a private static member variable named count in the Employee class, whenever the new object has created, increment the count variable. In addition, add a method named getCount that returns the value of this static variable.
pts Overload the operator as a friend function that needs two Employee objects as parameters, adds two employees names and salaries, assign them to new employee object, and then return new employee object.
pts The main function declares three objects of Employee. Add the first two employee objects and then display the third employees name and salary to the screen. In addition, display the value of static variable count.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
