Question
Using Using C# and visual Studio,Write a class that will allow for the addition, subtraction, multiplication and division of 2 complex numbers. The class must
Using Using C# and visual Studio,Write a class that will allow for the addition, subtraction, multiplication and division of 2 complex numbers. The class must use operator overloading for +, -, * and / operations. The class must have a ToString method that overrides the ToString method of the object class and properly formats the complex number ( 3.4 + 2i or -2.1 1.5i). You may use the following as a starting point for your class:
public class ComplexNumbers
{
public double Real
{
get ;
private set;
}
public double Imag
{
get ;
private set;
}
public ComplexNumbers(double r, double i)
{
Real = r;
Imag = i;
}
public static ComplexNumbers operator +(ComplexNumbers lhs, ComplexNumbers rhs)
{
double r = lhs.Real + rhs.Real;
double i = lhs.Imag + rhs.Imag;
return new ComplexNumbers(r, i);
}
Your console application to demonstrate the class's functioning must read the complex number components from a file called data.txt, add the first 2 complex numbers, subtract the next 2, multiply the next 2 and divide the last 2 and then write the results both to the screen and a file called outData.txt. Screen output should be properly formatted with the appropriate signs and the i for imaginary. The file output should be structured in the same manner as data.txt is formatted, with just the components. data.txt has the following contents and structure. The first value is the real component and the second is the imaginary component.
2 4
1.5 -3
2.3 -1.1
-1.8 2.5
3 5
7 -1
3 3
1 -2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started