CS_1C Homework 4-Friend Functions & Operator Overloading Solved

35.00 $

Category:

Description

5/5 - (1 vote)

Using HW03 …

  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.

  1. Overload << and >> operators to read in a CS1Cemployee object

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

Your output should be easy to follow and contain output only from hw04.

Extra Credit [+5 pts]

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 Fall 2018 TTH HW04 50pts Due: Tu 9/11/2018

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

  • Friend_and_operator_overload-jdh2rg.zip