/* cpp_problems_02 */ /* struct and class */ // #1 Fill the blank /* Using struct, implement the complex number */ #include using namespace std; struct complex_t { double re; double im; }; void printcomplex (complex_t c) { // Fill this blank } complex_t add (complex_t c1, complex_t c2) { // Fill the blank } int main(void) { complex_t c1, c2; c1.re = 3; c1.im = - 4.0 / 5; c2.re = -2.5; c2.im = 5.0; printcomplex(c1); printcomplex(c2); printcomplex(add(c1,c2)); return 0; } /* result 3 - 0.8i -2.5 + 5i 0.5 + 4.2i */ // #2 Try to make another functions, // such as subtraction and multiplication. /* #3 http://www.cplusplus.com/doc/tutorial/templates/ Extend CVector to R^3 and implement +, *(scalar multiplication), and dot product */