Question

See Exercise 9.15 in the Chapter 9 Programming Exercise from the Book section for the description...

See Exercise 9.15 in the Chapter 9 Programming Exercise from the Book section for the description of this exercise.​

Sample Run

Enter the real part of the first complex number: 3.5

Enter the imaginary part of the first complex number: 6.5

Enter the real part of the first complex number: -3.5

Enter the imaginary part of the first complex number: 1

(3.5 + 6.5i) + (-3.5 + 1i) = (0.0 + 7.5i)

(3.5 + 6.5i) - (-3.5 + 1i) = (7.0 + 5.5i)

(3.5 + 6.5i) * (-3.5 + 1i) = (-18.75 - 19.25i)

(3.5 + 6.5i) / (-3.5 + 1i) = (-0.43396226415 - 1.98113207547i)

|(3.5 + 6.5i)| = 4.47213595499958.

In Python.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import math
#taking inputs for two complex numbers
r1=input("Enter the real part of the first complex number: ")
i1=input("Enter the imaginary part of the first complex number: ")
r2=input("Enter the real part of the second complex number: ")
i2=input("Enter the imaginary part of the second complex number: ")

#addition of two complex numbers
def add(r1,i1,r2,i2):
return r1+r2,i1+i2

#substraction of two complex numbers
def sub(r1,i1,r2,i2):
return r1-r2,i1-i2

#multiplication of two complex numbers
def mul(r1,i1,r2,i2):
return (r1*r2-i1*i2),(r1*i2+i1*r2)

#division of two complex numbers
def div(r1,i1,r2,i2):
r=(r1*r2+i1*i2)/(r2*r2+i2*i2)
i=(i1*r2-r1*i2)/(r2*r2+i2*i2)
return r,i

#absolute value of complex number
def abslt(r,i):
return math.sqrt(r*r+i*i)

#printing result
def prnt(r1,i1,r2,i2,r,i,c):
print("(%.2f + %.2fi) %c (%.2f + %.2fi) = (%.2f + %.2fi)")%(r1,i1,c,r2,i2,r,i)

r,i=add(r1,i1,r2,i2)
prnt(r1,i1,r2,i2,r,i,'+')

r,i=sub(r1,i1,r2,i2)
prnt(r1,i1,r2,i2,r,i,'-')

r,i=mul(r1,i1,r2,i2)
prnt(r1,i1,r2,i2,r,i,'*')

r,i=div(r1,i1,r2,i2)
prnt(r1,i1,r2,i2,r,i,'/')

val=abslt(r1,i1)
print("|(%.2f + %.2fi)| = %f")%(r1,i1,val)


OUTPUT:

Enter the real part of the first complex number: 3.5 Enter the imaginary part of the first complex number: 5.4 Enter the real

Add a comment
Know the answer?
Add Answer to:
See Exercise 9.15 in the Chapter 9 Programming Exercise from the Book section for the description...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING A complex number is a number in the form a + bi, where a...

    JAVA PROGRAMMING A complex number is a number in the form a + bi, where a and b are real numbers and i is V-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + di a + bi - (c +...

  • A complex number is a number in the form a + bi, where a and b...

    A complex number is a number in the form a + bi, where a and b are real numbers and i is sqrt( -1). The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + d)i a + bi - (c + di)...

  • I am trying to complete Chapter 9 exercise 9 in C# Programming: From Problem Analysis to...

    I am trying to complete Chapter 9 exercise 9 in C# Programming: From Problem Analysis to Program Design. I have both first name and last name textboxes, an account number textbox, and an initial balance textbox. I need to make error messages when the user doesnt enter their info, but can't figure out the if statements that i need to use. What would you suggest? Thanks

  • File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

    File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to successfully complete chapter 9 programming exercise #3. File Encryption and Decryption Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would...

  • 2. Enter, compile, and run Program 11.1. he same name as the ave a return type...

    2. Enter, compile, and run Program 11.1. he same name as the ave a return type nction as a member Chapter 11 Program 11.1 of this function the parameters include <iostream ing namespace std. *onging to the declaration section class Complex private: 1 double realPart; I notice the colon after the keyword pri eters, real ssigns the he func- ouble imaginary Part; maginaryPart. // function prototypes data // data member the key as also public: 11 again, notice the colon...

  • Python Programming Chapter 5 Programming Exercise Dinner Selection Program (60 points total) Pseudocode (10 points) As...

    Python Programming Chapter 5 Programming Exercise Dinner Selection Program (60 points total) Pseudocode (10 points) As the family cook, you know that the toughest question of the day is "What's for dinner?" You For decide to write a program to help you do days of meal planning for the entree, side and dessert. You will need to use random numbers and functions to complete the project. What's Dinner? • • • Start with a pseudocode (10 points). Write the pseudocode...

  • Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY. 8.36 (Latin square)...

    Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY. 8.36 (Latin square) A Latin square is an n-by-n array filled with n different Latin letters, each occurring exactly once in each row and once in each column. Write a program that prompts the user to enter the number n and the array of characters, as shown in the sample output, and checks if the input array is a Latin square. The characters are the first n...

  • FULL SCREEN PRINTER VERSION RACK NEXT Chapter 3, Section 1, Exercise 024 Topical Painkiller Ointment The...

    FULL SCREEN PRINTER VERSION RACK NEXT Chapter 3, Section 1, Exercise 024 Topical Painkiller Ointment The use of topical painkiller ointment or gel rather than pills for pain relief was approved just within the last few years in the US for prescription use only. Insurance records show that the average copayment for a month's supply of topical painkiller ointment for regular users is $30. A sample of size 75 regular users found a sample mean copayment of $27.90 Tarkan, L.,...

  • Programming language: PYTHON Prompt: You will be creating a program to show final investment amounts from...

    Programming language: PYTHON Prompt: You will be creating a program to show final investment amounts from a principal using simple or compound interest. First, get a principal amount from the user. Next, ask the user if simple or compound interest should be used. If the user types in anything other than these options, ask again until a correct option is chosen. Ask the user to type in the interest rate as a percentage from 0 to 100%. Finally, ask the...

  • Bucket Management – In this programming exercise you will create a simple bucket management program according...

    Bucket Management – In this programming exercise you will create a simple bucket management program according to the following customer specifications: Write the definition of a class Bucket, to implement the properties and functions of a bucket. The bucket must be Cylinder shaped of any dimension. (20%) The class should have the instant variables to store the height (in feet), radius (in feet), amount (in cubic feet) of water in the bucket, the rate (in gallons / minute), at which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT