乐趣区

关于后端:PIC-10B-问题求解

PIC 10B Homework 4 Due Friday, Feb 26
Problem 1:
Using good coding practices, design your own ComplexVector class for vectors whose elements
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 i
2 = −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
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 + 5 n2
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.

退出移动版