Home / Expert Answers / Computer Science / please-use-c-and-include-the-main-cpp-cpp-and-h-file-thank-you-hint-for-main-function-yo-pa830

(Solved): Please use C++ and include the main.cpp, .cpp, and .h file. Thank you!Hint For main function, yo ...



Please use C++ and include the main.cpp, .cpp, and .h file. Thank you!

student submitted image, transcription available below

student submitted image, transcription available below

Hint – For main function, you can use the following:

int main() {

// User input a Complex Number:

double real, imag;

cout << "Enter the Complex Number (a + bi format, separated by spaces): ";

cin >> real >> imag;

Complex input_f0 = Complex(real,imag);

int n;

cout<<"Enter n: ";

cin>> n;

cout<< ComplexSequence(input_f0,n)<<endl;

int m;

cout<<"Enter size of Complex vector m: ";

cin>> m;

// User input for the first complex vector

cout << "Enter the elements of the first complex vector (a + bi format, separated by spaces)

vector<Complex> inputElements1;

for (int i = 0; i < m; i++) {

double real, imag;

cin >> real >> imag;

inputElements1.push_back(Complex(real, imag));

}

ComplexVector v1(inputElements1);

// User input for the second complex vector

cout << "Enter the elements of the second complex vector (a + bi format, separated by spaces

vector<Complex> inputElements2;

for (int i = 0; i < m; i++) {

double real, imag;

cin >> real >> imag;

inputElements2.push_back(Complex(real, imag));

}

ComplexVector v2(inputElements2);

cout << "v1 + v2 = " << v1 + v2 << endl;

cout << "v1 - v2 = " << v1 - v2 << endl;

cout << "v1 * v2 = " << v1 * v2 << endl;

cout << "v1 / v2 = " << v1 / v2 << endl;

return 0;

}

student submitted image, transcription available below

Problem : Design the ComplexVector class. Design your own ComplexVector class for vectors whose elements are complex numbers. Provide an implementation for - term by term addition - term by term subtraction, - term by term multiplication - term by term division - the stream output operator. Such that if v1 and v2 are ComplexVector objects, then one can compute v1 + v2, etc. Hint : you may want to create a Complex class separately. Complex numbers are expressed in the form , where is the real part, is the imaginary part, and is the imaginary unit satisfying . Print your complex numbers using this representation. When adding (or subtracting) two complex numbers, add (or subtract) their real parts and imaginary parts separately. The multiplication of two complex numbers is defined by, while division is given by, Instructions After declaring and defining the ComplexVector class and its member functions, do the following: 1. Using your newly defined ComplexVector class, write a recursive function to print the n-th term in the sequence from equation [3): 2. Using the vectors and of size , write a main function that checks , v1 * v2, and v1 / v2 by printing them to the console. Compile your code and run your program to check for compile-time errors and logic errors. Submit your header files and source codes to Gradescope in separate files. Figure 1 shows the sample outputs. Enter the Complex Number ( format, separated by spaces): 11 Enter n: 2 Enter size of Complex vector Enter the elements of the first complex vector format, separated by spaces): 1122 Enter the elements of the second complex vector format, separated by spaces): 3311 v1 v2 Program ended with exit code: Figure 1: Sample output. For the stream output operator, consider following for the Complex Class friend std::ostream\& operator std::ostream\& os, const Complex\& complex) \{ os complex.real complex.imag ; return os; \} For the ComplexVector: friend std::ostream\& operator (std::ostream\& os, const ComplexVector\& vector) \{ for (const Complex\& complex : vector.elements) \{ os complex " "; \} return os; \}


We have an Answer from Expert

View Expert Answer

Expert Answer



We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe