#include using namespace std;

struct Complex { double real; // 实部 double imag; // 虚部 };

void Create(double x, double y, Complex* z) { z->real = x; z->imag = y; }

void Add(Complex z1, Complex z2, Complex* sum) { sum->real = z1.real + z2.real; sum->imag = z1.imag + z2.imag; }

void Subtract(Complex z1, Complex z2, Complex* difference) { difference->real = z1.real - z2.real; difference->imag = z1.imag - z2.imag; }

void Multiply(Complex z1, Complex z2, Complex* product) { product->real = z1.real * z2.real - z1.imag * z2.imag; product->imag = z1.real * z2.imag + z2.real * z1.imag; }

void Get_RealPart(Complex z, double* e) { *e = z.real; }

void Get_ImagPart(Complex z, double* e) { *e = z.imag; }

int main() { Complex z1, z2, sum, difference, product; double realPart, imagPart;

Create(1.5, 2.5, &z1);
Create(2.0, -1.5, &z2);

Add(z1, z2, &sum);
Subtract(z1, z2, &difference);
Multiply(z1, z2, &product);
Get_RealPart(z1, &realPart);
Get_ImagPart(z2, &imagPart);

cout << 'Sum: ' << sum.real << ' + ' << sum.imag << 'i' << endl;
cout << 'Difference: ' << difference.real << ' + ' << difference.imag << 'i' << endl;
cout << 'Product: ' << product.real << ' + ' << product.imag << 'i' << endl;
cout << 'Real part of z1: ' << realPart << endl;
cout << 'Imaginary part of z2: ' << imagPart << endl;

return 0;

}


原文地址: https://www.cveoy.top/t/topic/m1I3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录