Question: PLEASE CODE THIS IN C++, ALSO PLEASE READ ALL THE INSTRUCTIONS AND DON'T CODE RANDOMLY!! ============================================================================ The purpose of this assignment is to make sure
PLEASE CODE THIS IN C++, ALSO PLEASE READ ALL THE INSTRUCTIONS AND DON'T CODE RANDOMLY!!
============================================================================
The purpose of this assignment is to make sure that you know how to write a program that uses classes, friend functions, and operator overloading.
PROGRAM SPECIFICATION
For the assignment, we will modify a program that you created as your solution for assignment C, the complex numbers using classes. Recall the program created a class called Complex for performing arithmetic with complex numbers. The class enables so-called complex numbers. These are numbers of the form realPart + imaginaryPart * i
where i is:
For this assignment, you will make changes to the previous coding to now include the following upgrades:
Modify the class to enable input and output of complex numbers via overloaded + and - operators, respectively (addition and subtraction).
Modify the class to enable input and output of complex numbers via overloaded = and * operators, respectively (assignment and multiplication).
Modify the class to enable input and output of complex numbers via overloaded >> and << operators, respectively (you should remove the print function from the class). Use friend functions to accomplish this.
Overload the == and != operators to allow comparisons of complex numbers.
Add friend member functions to enable input and output of complex numbers via overloaded >> and << operators, respectively (you should remove the print function from the class).
Change the Complex class definition, the Complex class member-function definitions, and modify the driver program as appropriate. Please use the following code and replace your main function, or driver function, with the test code included below. Use these test cases now, and execute the test cases successfully to ensure full credit.
int main()
{
for (double i = 1; i < 10; ++ i)
{
Complex y{i * 2.7, i + 3.2};
Complex z{i * 6, i + 8.3};
Complex x;
Complex k;
std::cout << "Enter a complex number in the form: (a, b) ? ";
std::cin >> k; // demonstrating overloaded >>
std::cout << "x: " << x << " y: " << y << " z: " << z << " k: "
<< k << ' '; // demonstrating overloaded <<
x = y + z; // demonstrating overloaded + and =
std::cout << " x = y + z: " << x << " = " << y << " + " << z << ' ';
x = y - z; // demonstrating overloaded - and =
std::cout << " x = y - z: " << x << " = " << y << " - " << z << ' ';
x = y * z; // demonstrating overloaded * and =
std::cout << " x = y * z: " << x << " = " << y << " * " << z << " ";
if (x != k) { // demonstrating overloaded !=
std::cout << x << " != " << k << ' ';
}
std::cout << ' ';
x = k;
if (x == k) { // demonstrating overloaded ==
std::cout << x << " == " << k << ' ';
}
std::cout << std::endl;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
