Starting from:

$30

CS1C-Homework 4 Friend Functions & Operator Overloading Solved

1.    Write and test a friend function that checks to see if the phone number of a C1SCEmployee object is equal to the phone number of a Programmer object. Test equal and not equal scenarios.  (You will need to call your ChangePhoneNumber method)

 

2.   Overload the equality operator to see if the phone number of two C1SCEmployees are the same.  Test equal and not equal scenarios. (You will need to call your ChangePhoneNumber method)

 

3.   Write an addition member function that adds an integer to a CS1Cemployee’s age (make sure the integer is a passed parameter).  The output should state how many years were added to the age.

 

4.   Overload the addition operator to add a constant to a

CS1Cemployee’s age. For example: StarC1SCEmployee = StarC1SCEmployee + 2.  The output should state how many years were added to the age.

 

5.   Overload << and operators to read in a CS1Cemployee object

(e.g. cin myEmployee and cout << myEmployee)

 



Extra Credit

 

Overload the pre & post increment operators to increment an

CS1Cemployee’s age. Test pre/post increment operations. Output HW04 – Friend Functions & Operator Overloading [50 pts]

the values of CS1Cemployee objects before and after pre/post increment operations as well as after assignment takes place.

Demonstrate how pre/post increment operators are different.

Which overloaded operator incurs the most overhead?

 

Use the command script to capture your interaction compiling and running the program, including all operations, as shown below:

 


 

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ script hw04.scr Script started, file is hw04.scr cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ date

...

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ ls -l

...

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ make all

...

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ ls -l

...

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ ./hw04

 

... // print out test results for the friend & member functions from steps 1, 3

... // print out test results for the overloaded operators from steps 2, 4, 5

 

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ exit Script done, file is hw04.scr

cs1c@cs1c-VirtualBox ~/cs1c/hw/04 $ make tar

...

More products