// complex.cpp : 此文件包含 “main“ 函数。程序执行将在此处开始并结束。
//
#include
using namespace std;
class complex {
public:
double x;
double y;
complex();
complex(double a double b);
friend ostream& operator <<(ostream& osconst complex& a);
friend istream& operator>>(istream& is complex& a);
friend complex operator ~(const complex& a);
complex operator -(const complex& a) {
complex result;
result.x = this->x - a.x;
result.y = this->y - a.y;
return result;
}
complex operator +(const complex& a) {
complex result;
result.x = this->x + a.x;
result.y = this->y + a.y;
return result;
}
complex operator *(const complex& a) {
complex result;
result.x = (this->x) * a.x - (this->y) * a.y;
result.y = (this->x) * a.y + (this->y) * a.x;
r
评论
共有 条评论