Question

write c++ code to read two complementary complex numbers and output their multiplication and division using...

write c++ code to read two complementary complex numbers and output their multiplication and division using separate functions. Print each of the values in the form a+ib or a-ib. Write C++ program and write algorithm in words for the problem. Note: A complex number a +ib has complementary complex number a-ib.

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

Please find the code below:::

main.cpp

#include<iostream>
#include<cmath>
using namespace std;


class complex
{
private:
   float rel;
   float img;
public:
   complex(float relIn,float imgIn){
       rel = relIn;
       img = imgIn;
   }
   complex(){
       rel = 0;
       img = 0;
   }
   complex operator *(complex s2){
       float a,b;
       a=((rel)*(s2.rel))-((img)*(s2.img));
       b=((rel)*(s2.img))+((s2.rel)*(img));
       return complex(a,b);
   }


   complex operator /(complex s2){
       float a,b;
       float part = s2.rel*s2.rel +s2.img*s2.img;
       a = (rel*s2.rel + img*s2.img)/part;
       b = (img*s2.rel - rel*s2.img)/part;
       return complex(a,b);
   }


   void print(){
       cout<<rel;
       if(img>=0){
           cout<<"+"<<img<<"i"<<endl;
       }else{
           cout<<img<<"i"<<endl;
       }
   }
};

int main()
{
   float real,img;
   cout<<"Enter real part of complex number : ";
   cin>>real;
   cout<<"Enter imaginary part of complex number : ";
   cin>>img;


   complex num1(real,img);
   complex num2(real,-1*img);

   cout<<"Numer1 : ";num1.print();
   cout<<"Numer2 : ";num2.print();
   complex mul =num1*num2;
   cout<<"Multiplication : ";mul.print();

   complex div =num1/num2;
   cout<<"Division : ";div.print();

   return 0;
}

output:
모 Console X くterminated> CPP Workspace.exe [C/C++ Application] C:NUsers Mohammad Shah Enter real part of complex number 1 Ent

Add a comment
Know the answer?
Add Answer to:
write c++ code to read two complementary complex numbers and output their multiplication and division using...
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
  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • C++ PROBLEM STATEMENT: Devise an algorithm to perform the optimal multiplication of two complex numbers SPECIFICATIONS:...

    C++ PROBLEM STATEMENT: Devise an algorithm to perform the optimal multiplication of two complex numbers SPECIFICATIONS: The multiplication of two complex numbers z1 = a+ bi and z2 = c+ di can be done in only three multiplications. Write an algorithm that uses only three multiplications (correct code, syntax)

  • USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write...

    USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...

  • C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex...

    C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √ −1. You should represent a complex number here as two values of type double. You should name the variables real and imaginary. You can call the...

  • need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re,...

    need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary parts of a complex number }; typedef struct _cplx Complex; // Initializes a complex number from two real numbers Complex CmplxInit(double re, double im) Complex z = { re, im }; return z; // Prints a complex number to the screen void CmplxPrint(Complex z) // Not printing a newline allows this to be printed in the middle of...

  • Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations...

    Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations of two numbers. Please use functions and switch statements. Please provide option to the user to continue the program after each operation. Please provide option to 'Exit' the program also

  • Write in a program in C. NOTE: in mathematics, division by zero is undefined. So, in...

    Write in a program in C. NOTE: in mathematics, division by zero is undefined. So, in C, division by zero is always an error. Given a int variable  named  callsReceived and another int variable  named  operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do). HOWEVER: if any value read in is not valid input, just print the message "INVALID".

  • ​​​​​​ C Programming Language The operation of multiplication for positive integers can be expressed as: A.B=2...

    ​​​​​​ C Programming Language The operation of multiplication for positive integers can be expressed as: A.B=2 1 A for (A+[A.(B-1)] B=1 for B>1 Task 1 (for 1 point) is to write a program that will read and print on the screen the values of two integers (A and B) given by user as command line parameters. Task 2 (for 1 point) is to write a program that will calculate the result of the multiplication of two integers. It should print...

  • READ CAREFULLY AND CODE IN C++ Dynamic Programming: Matrix Chain Multiplication Description In this assignment you...

    READ CAREFULLY AND CODE IN C++ Dynamic Programming: Matrix Chain Multiplication Description In this assignment you are asked to implement a dynamic programming algorithm: matrix chain multiplication (chapter 15.2), where the goal is to find the most computationally efficient matrix order when multiplying an arbitrary number of matrices in a row. You can assume that the entire input will be given as integers that can be stored using the standard C++ int type and that matrix sizes will be at...

  • write a c++ code to read multiple integers from input.dat until the end of file. Edit...

    write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...

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