Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

self-test exercise 17 asked you to overload the operator >> and the operator <<

ID: 3636715 • Letter: S

Question

self-test exercise 17 asked you to overload the operator >> and the operator << for a class pairs. Complete and test this exercise. Implement the default constructor and the constructors with one and two int parameters. The one parameter constructor should initialize the first member of the pair; the second member of the pair is to be 0.
Overload binary operator to add pairs according to the rule
(a, b) (c, d) = (a c, b d)
Overload operator- analogously.
Overload operator* on pairs and int according to the rule
(a, b)*c= (a*c, b*c)
Write a program to test all the member functions and overloaded operators in your class definition.

Explanation / Answer

Exercise 1: Resistor Class Operator Overloading (20 points) Objective: Create a C++ Class that includes overloaded operators. Recall from last week's lab that we designed and implemented two resistor classes. We will use our lab work from last week and enhance the base resistor class by overloading several operators. You can use the lab solution from last week as your starting point. There is no need for the fancyResistorClass so you can eliminate all of the code related to this class. Here is what you need to do: Create a ResistorClass overloaded assignment (=) operator function which shall do the following: Overload the assignment operator ( = ) to assign all m_dptrRes data values of an object of class ResistorClass to another object of class ResistorClass. Remember to use deep copying. Be sure to copy the max and min resistance values. Copy m_sptrResName using the strcpy_s function (see lab 6 for details on the strcopy_s function). Print the message "Overloaded Resistor Assignment = Operator Called" Create a ResistorClass overloaded addition operator function which shall do the following: Overload the addition operator ( + ) to perform series resistance addition of the nominal values ( m_dptrRes[0]) of two Resistor Class objects. In other words, the nominal values of the two resistor objects will be added together. Compare the tolerance values ( m_dptrRes[1]) of two Resistor Class objects and set the tolerance equal to the larger of the two tolerance values. Print the message "Overloaded Resistor Series Resistance Operator Called" Create a ResistorClass overloaded logical OR operator function which shall do the following: Overload the logical OR operator ( || ) to calculate the equivalent parallel resistance of the nominal values ( m_dptrRes[0]) of two Resistor Class objects. The formula for calculating parallel resistance is: NominalValue1 * NominalValue2 / (NominalValue1 + NominalValue2) Compare the tolerance values of the two objects and set the tolerance value ( m_dptrRes[1]) equal to the larger of the two tolerance values. Print the message "Overloaded Resistor Parallel Resistance Operator Called" Exercise 2: Test the overloaded operators (20 points) Objective: Create a program that tests each overloaded operator to ensure it works properly. Test the ResistorClass overloaded operators by performing the following tasks: Instantiate four ResistorClass objects: Res1, Res2, ResSeries and ResParallel Instantiate all ResistorClass objects using the parameterized constructor. Calculate ResSeries = Res1 + Res2 Calculate ResParallel = Res1 || Res2 Display the values of the ResSeries and ResParallel objects End program Optional Information: Programming Language: c++ Compiler: dev c