Knowee
Questions
Features
Study Tools

Write a class for addition of complex numbers. The program should ask for real and imaginary part of complex numbers and using function it should add the real part to real part of the number and imaginary part to imaginary part of the number.

Question

Write a class for addition of complex numbers. The program should ask for real and imaginary part of complex numbers and using function it should add the real part to real part of the number and imaginary part to imaginary part of the number.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python class that accomplishes this:

class ComplexNumber:
    def __init__(self, real=0, imag=0):
        self.real = real
        self.imag = imag

    def get_data(self):
        print(f'{self.real}+{self.imag}j')

    def add(self, num):
        self.real = self.real + num.real
        self.imag = self.imag + num.imag
        return self.get_data()

# Create first complex number

This problem has been solved

Similar Questions

Write a Java program to find the addition, subtraction, multiplication, and division of two complex numbers using inheritance. Create an abstract class called Complex. From this extends the child classes Addition, Subtraction, Multiplication, and Division. All of these child classes should contain the same methods.Input format :The input consists of four double-type variables, which denote the real and imaginary parts of the first and second complex numbers, respectively.Output format :The output consists of the addition, subtraction, multiplication, and division of the two complex numbers.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :2 64 2Output 1 :Addition: 6.0000 +8.0000 iSubtraction: -2.0000 +4.0000 iMultiplication: -4.0000 +28.0000 iDivision: 1.0000 +1.0000 i

Create a Complex class to represent complex numbers. Overload the addition (+), subtraction (-), multiplication (*), and division (/) operators for complex numbers. The prompt ask 2 complex number from the user and display the respective output for the user input.

operations on complex numbers Write a program to find out the addition and multiplication of two complex numbers using structures and functions. Note: Write the code in the functions readC(), display(), add() and product().

Create a C++ programme that accomplishes all arithmetic operations on two complex objects, including addition, subtraction, multiplication, and division. (X + i * Y) represents the Complex Object (Where X and Y are two real numbers and 'i' is an Imaginary). As a programmer, create a class called "COMPLEX" containing the data members X and Y and also getData() and putData() methods to pefrom read and write for the above said Data Members. Define a separate functions for the operations such as Addition, Subtraction, Multiplication, and Division.Input :Read the Two Complex Objects (Each with X and Y)Output :Addition of Two Complex ObjectsSubtraction of Two Complex ObjectsMultiplication of Two Complex ObjectsDivision of Two Complex ObjectsNote :Both X and Y are Non-Negative, otherwise print "Invalid"Define a separate functions with return type and with arguments of two complext objects.

Write a program overloading arithmetic operators to add two complex numbers using oops c++

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.