Question: Please help me with these C++ questions. If possible please screenshot the outputs. thank you so much! 8. Enter employee.cpp, which can be found below.
Please help me with these C++ questions. If possible please screenshot the outputs. thank you so much!
8. Enter employee.cpp, which can be found below. Notice that we can make an entire struct a friend of another struct. All the member functions of accountant have access to private elements of employee.
a) Create struct accountant in the file employee.cpp. Within the struct, declare a function payroll() which shows an employee object being passed by value into the payroll() function. Submit the code.
b) Define the payroll() function which accesses and prints the private information about employee. Simply select them as if they were public members of the struct. Convince yourself that you can compile the program. Submit the code.
c) To show this isn't normally possible, comment out the friend declaration in the employee struct. What happens when you compile? Submit the code.
d) Create a new struct called boss with a member function called seepay(employee). This should precede the employee declaration. To do this, you must first tell the compiler there is a struct somewhere called employee with a name declaration: struct employee; Submit the code.
e) A type name declaration has no body, so the compiler knows the name exists, but not how big it is. Now create a declaration inside struct employee which says "the seepay() function of struct boss has friend status, but only that function." Submit the code.
f) See if you can change the friend declaration in struct employee so it only gives access to accountant::payroll(), and not the entire struct accountant. Submit the code.
SOURCE CODES BELOW:
// employee.cpp entire structs can be friends
struct employee {
private:
int salary;
int benefitLevel;
public:
void initialize(
int startingPay);
void raise(float percent);
friend struct accountant;
};
int main() {
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
