Question: Q4. Create a class to perform addition operation on complex data. The program should ask for real and imaginary part of two complex numbers, and
Q4. Create a class to perform addition operation on complex data. The program should ask for real and imaginary part of two complex numbers, and display the real and imaginary parts of their sum.
Note: Declare a class with two private double type member variables for the real and imaginary parts respectively. Define a constructor taking two arguments of doubles for the real and imaginary parts, respectively. Define two functions named get_rl and get_im for returning the real and imaginary parts respectively. In the main function, input two complex numbers, each with real and imaginary parts respectively, e.g. nu1 and nu2 for the first complex number (comp1) and nu3 and nu4 for the second complex number (comp2). Build two complex number objects, and perform addition operation, by adding their real and imaginary parts (double real = comp1.get_rl() +comp2.get_rl();double imagin = comp1.get_im() + comp2.get_im();), and then print the sum of the two complex numbers (print real and imagin respectively).
Q5. Based on Q4, add a public member function named add to class Complex. The add function takes an argument of Complex number and add the number to the current complex number, and return the result (a complex number). Test the add function in the main function (Complex com3 = comp1.add(comp2);), and print the real and imaginary parts of com3. Define another add function to the class Complex, which takes two arguments of complex numbers and returns the sum of these two complex numbers.
// Complex.cpp
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
