Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this problem you will create a complex number class called Complex that will create a number of the form a+bi where a is the
In this problem you will create a complex number class called Complex that will create a number of the form a+bi where a is the real part of type float, b is the imaginary part of type float, and i is the complex number defined as the square root of-1. Your Complex object will contain the following information: 1. Real part (default-0.0) 2. Imaginary part (default 0.0) sub should return a new Complex 2. The methodtruedivshould return a new Complex object unless there is a Your complex number class must include methods for overriding add mul . tuediv and str 1. The methods add sub andl object (do not mutate the original Complex object) divide by zero error! In this case, retum None and infon the user that there was a divide by zero error in your main function. 3. The method str should retum a string of the complex number in the form "a+bi" where a is the real part and b is the imaginary part a. If both a and b are positive, retum a string in the form "a+bi b. If b is negative, return a string of the complex number in the form a-bi" c. If the real part is zero, retum the imaginary part d. If the imaginary part is zero, return the real part e. If both real and imaginary parts are zero return "O" Note: if you are unsure of how to perform complex number arithmetic, a guide is provided at the end of Problem A. Once your complex number class is created, write a main function outside of Complex that takes no arguments. It will ask for input four times (you can assume the user will enter valid input--either floats or integers); once for the real part of one complex number, once for the imaginary part of the same complex number, once for the real part of a second complex number, and once for the imaginary part of the second compkex number. After creating two Complex objects using the inputted values, print both complex numbers, their sum, difference, product, and quotient. Here is a sample output of the program: Enter the real part of the first complex number: 200 Enter the imaginary part of the first complex number: 0 Enter the real part of the second complex number: 10 Enter the imaginary part of the second complex number: 10 C1-200.0 C210.0+10.0 C1+c2210.0+10.0i C1-C2190.0-10.0 c1C2 ? 200 0 . 0 +2000 .0i C1/C2 10.0-10.0 Here is a sample output of the program when a divide by zero error occurs: Enter the real value of the first complex number 5 Enter the imaginary value of the first complex number 5 Enter the real value of the second complex number: 0 Enter the imaginary value of the second complex number: 0 C1-5.0+5.0i C20 C1+C2 5.0+5.0 C1-c2 -5.0+5.0 C1/C2None: Divide by Zero Error
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