PIC 10B Homework 4 Due Friday, Feb 26 Problem 1: Using good coding practices, design your own ComplexVector class for vectors whose el- ements are complex numbers. Provide an overloading...

Complex Numbers


PIC 10B Homework 4 Due Friday, Feb 26 Problem 1: Using good coding practices, design your own ComplexVector class for vectors whose el- ements are complex numbers. Provide an overloading implementation for term by term addition, subtraction, multiplication, division, and 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 a+bi, where a is the real part, b is the imaginary part, and i is the imaginary unit satisfying i2 = −1. 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, (a + bi)(c + di) = (ac− bd) + (bc + ad)i, (1) while division is given by, a + bi c + di = ac + bd c2 + d2 + bc− ad c2 + d2 i. (2) Using your newly defined ComplexVector class, write a recursive function to print the first 6 terms in the sequence from equation (3) to a file titled “ComplexSequence.txt”. fn+1 = (2 + 3 i)n 7 + 5n2 i fn, (3) f1 = 1 + i (4) Using the vectors v1 and v2 , v1 = { 2 + 4 i, 3 + 5 i, -1 - 3 i , 8 + 10 i } v2 = { -10 + 3.5 i, 4 + 7.3 i, 2 - 8 i, 10 -142 i}, write a main function that checks v1 + v2, v1 - v2, v1 * v2, and v1 / v2 by printing them to the console. Figure 1 shows the sample outputs. Due Friday, Feb 26 Homework 4 PIC 10B Figure 1: Sample output. Good Coding Practices: ˆ think about cross-platform. Don’t use Windows or Mac only commands. For example, pause == cin.get() twice, write many \n vs. system(clear) or system(’cls). ˆ passing objects by reference & or const & when possible ˆ using field initializer list when possible in all constructors Instructions for submission: ˆ Name your files exactly hw4.cpp, Complex.h, Complex.cpp, ComplexVector.h, and ComplexVector.cpp. ˆ You may not use #include "stdafx.h". ˆ Add code description in the comment at the beginning of the file. A sample description may look like: /* PIC 10B 2A, Homework 1 Purpose: Tic-tac-toe game Author: Hanqin Cai Date: 10/10/2019 */ ˆ Submit your header files and source codes to CCLE in separate files. Only .h and .cpp files should be uploaded.
Feb 26, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here