Question
Please provide source code, make a program that follows everything on this doc.
te a complete program that accomplishes the following tasks Wri Display a friendly greeting to the user Prompt the user for a complex number, call it a. Accept that complex number using cin. Display that complex number using cout. Prompt the user for a complex number, call it b Accept that complex number using cin. Display that complex number using cout. Display a line of code that states whether or not a is the same as b, using Display a line of code that states whether or not a is different from b, using! Create a new complex number; call it c Make c the sum of a and b, using c-ab Display the result using cout Add a to c using c-a Display the result using cout Subtract b from c using cb Display the result using cout Make c the difference of a and b, using c-a-b Display the result using cout Make c the product of a and b, using c ab (see note below) Display the result. Create complex numbers x, y, and z, and display the results Display a double type-cast to a ComplexNumber Display a ComplexNumber type-cast to a double The product of two complex numbers is found as follows: if a-a and b-b,+b,i then the real part of a *b -a, b-a*b, and the imaginary part of a *b- a, *b,+a,*b,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<math.h>

using namespace std;

struct complexNumber

{

float real;

float imaginary;

}a,b,c,x,y,z;

int main()

{

cout<<"Hello user!\n";

cout<<"Enter real and imaginary part of 1st complex number:";

cin>>a.real>>a.imaginary;

cout<<"Entered first complex number= "<<"("<<a.real<<")"<<"+"<<"("<<a.imaginary<<")"<<"i";

cout<<"\nEnter real and imaginary part of 2nd complex number:";

cin>>b.real>>b.imaginary;

cout<<"Entered second complex number= "<<"("<<b.real<<")"<<"+"<<"("<<b.imaginary<<")"<<"i";

if(a.real==b.real && a.imaginary==b.imaginary)

{

cout<<"\ncomplex numbers a and b are equal.";

}

if(a.real!=b.real || a.imaginary!=b.imaginary)

{

cout<<"\ncomplex numbers a and b are not equal.";

}

c.real=a.real+b.real;

c.imaginary=a.imaginary+b.imaginary;

cout<<"\nAddition of a and b: "<<"("<<c.real<<")"<<"+"<<"("<<c.imaginary<<")"<<"i";

c.real+=a.real;

c.imaginary+=a.imaginary;

cout<<"\nAddition of a to c: "<<"("<<c.real<<")"<<"+"<<"("<<c.imaginary<<")"<<"i";

c.real-=b.real;

c.imaginary-=b.imaginary;

cout<<"\nSubtraction of b from c: "<<"("<<c.real<<")"<<"+"<<"("<<c.imaginary<<")"<<"i";

c.real=a.real-b.real;

c.imaginary=a.imaginary-b.imaginary;

cout<<"\nSubtraction of a and b: "<<"("<<c.real<<")"<<"+"<<"("<<c.imaginary<<")"<<"i";

c.real=((a.real)*(b.real))-((a.imaginary)*(b.imaginary));

c.imaginary=((a.real)*(b.imaginary))+((b.real)*(a.imaginary));

cout<<"\nProduct of a and b: "<<"("<<c.real<<")"<<"+"<<"("<<c.imaginary<<")"<<"i";

x.real=y.real=z.real=c.real;

x.imaginary=y.imaginary=z.imaginary=c.imaginary;

cout<<"\ncomplex number x= "<<"("<<x.real<<")"<<"+"<<"("<<x.imaginary<<")"<<"i";

cout<<"\ncomplex number y= "<<"("<<y.real<<")"<<"+"<<"("<<y.imaginary<<")"<<"i";

cout<<"\ncomplex number z= "<<"("<<z.real<<")"<<"+"<<"("<<z.imaginary<<")"<<"i";

x.real=(double)x.real;

x.imaginary=(double)x.imaginary;

cout<<"\ncomplex number x type-cast to a double= "<<"("<<x.real<<")"<<"+"<<"("<<x.imaginary<<")"<<"i";

}

Add a comment
Know the answer?
Add Answer to:
Please provide source code, make a program that follows everything on this doc. te a complete...
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
  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • This is a fill in the code type: // FILL IN THE CODE - Write a...

    This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() {   int num1;       // holds 1st number   int num2;       // holds 2nd number   int result;       // holds result of multiplication   int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number   int *num2Ptr...

  • Using a programming language of your choice, write a complete and fully functional program that uses...

    Using a programming language of your choice, write a complete and fully functional program that uses reference and pointer types to swap two integer numbers. The two numbers are read in separately by the program’s user. Use a proper prompt for each number read in. a. Use one function that uses formal parameter reference type to swap the two numbers b. Use another function that uses formal parameter pointer type to swap the two numbers. c. In the main or...

  • c++ I am suppose to write a function that gets a number from a user, say...

    c++ I am suppose to write a function that gets a number from a user, say 3.123456789 and then the program gets another number from the user which is used to find out how many decimal digits we want rounded to. So if the user inputs 3 then the number would turn into 3.123 then we are suppose to add two digits next to the rounded number so it would turn into 3.12300. the rounding is suppose to be done...

  • Write a program in C++. You need everything everythihng given You will create a function that...

    Write a program in C++. You need everything everythihng given You will create a function that validates input. It should accept only non-negative integers. If the input is incorrect the function should throw an exception. The exception will not be caught in the function. You will create a function that reads in 2 integer values. One is a number that will be raised to the power of the second. So if 5 and 6 are entered the result would be...

  • this should be a code for C++ the source code file so the program will operate...

    this should be a code for C++ the source code file so the program will operate as described below. These are the software requirements for the project. When the program runs, it shall display the text as shown on lines 1-11 in the example below. Next, it shall display a prompt message asking the user to enter his or her yearly salary. Next, it shall shall read the user's salary from the keyboard (in the example below, user input is...

  • IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...

    IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...

  • Create a program with the main function and one additional function. The additional function asks for...

    Create a program with the main function and one additional function. The additional function asks for input from the user and returns the output back to the main function for display. This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you #include <iostream> using namespace std; int sum (int, int); int main() {     int n1, n2, total;               cout << "Enter two numbers...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

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