Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started