I need to write a program in C++ with the following instructions below. Please d
ID: 3879481 • Letter: I
Question
I need to write a program in C++ with the following instructions below. Please don't give me code in another language.
Take as input four floating point values (in this order, as indicated): 1 value and an imaginary value for the first complex nu D. a real value and an imaginary value for the second complex number Print the following four results: the sum, the difference, the product and the quotient of the 2 complex numbers. You will use exactly the following format: a. Each result on a single line (thus 4 lines printed) b. The precision is to two decimal point of accuracy (see note lc below) c. output looks like the following exactly: 1 + 21 that is, a float, a space, a plus sign, a space, a float followed directly by the letter iExplanation / Answer
#include <iostream>
#include<iomanip>
using namespace std;
void multiply(float r1, float r2, float img1, float img2){
float real;
float img;
real = r1 * r2 - img1 * img2;
img = r1 * r2 + img1 * img2;
cout<<" Multiply of two number is: "<<std::setprecision (2) <<std::fixed<<real<<" + "<<std::setprecision (2) <<std::fixed<<img<<"i ";
}
void addComplex(float r1, float r2, float img1, float img2){
float real;
float img;
real = r1 + r2;
img = img1 + img2;
cout<<" Addition of complex number is "<<std::setprecision (2) <<std::fixed<<real<<" + "<<std::setprecision (2) <<std::fixed<<img<<"i ";
}
void subtract(float r1, float r2, float img1, float img2){
float real;
float img;
real = r1 - r2;
img = img1 - img2;
cout<<" Subtraction of complex number is "<<std::setprecision (2) <<std::fixed<<real<<" + "<<std::setprecision (2) <<std::fixed<<img<<"i ";
}
int main()
{
float real1, real2;
float imaginary1, imaginary2;
cout << " Enter real part of first complex number";
cin>>real1;
cout<<" Enter real part of second complex number";
cin>>real2;
cout << " Enter imaginary part of first complex number";
cin>>imaginary1;
cout<<" Enter imaginary part of second complex number";
cin>>imaginary2;
addComplex(real1, real2, imaginary1, imaginary2);
subtract(real1, real2, imaginary1, imaginary2);
multiply(real1, real2, imaginary1, imaginary2);
return 0;
}