// Note:Your choice is C++ IDE
#include <iostream>
#include <cmath>
using namespace std;
/*
向量x=(x1,x2,x3,x4)和y=(y1,y2,y3,y4)
通过运算符重载实现向量之间的加减
*/
class vectors
{
private:
double x1,x2,x3,x4;
public:
vectors(){x1=0;x2=0;x3=0;x4=0;}//定义构造函数
vectors(double y1,double y2,double y3,double y4){x1=y1;x2=y2;x3=y3;x4=y4;}//构造函数重载
vectors operator + (vectors &x);
vectors operator - (vectors &x);
double len(vectors &x);
//~vectors(){};
void display(vectors x);
};
double vectors :: len(vectors &x)
{ return sqrt(pow(x.x1,2) + pow(x.x2,2) + pow(x.x3,2)+ pow(x.x4,2));}
vectors vectors :: operator + (vectors &x)
{
vectors v;
v.x1 = x1 + x.x1;
v.x2 = x2 + x.x2;
v.x3 = x3 + x.x3;
v.x4 = x4 + x.x4;
return v;
}
vectors vectors :: operator - (vectors &x)
{
vectors v;
v.x1 = x1 - x.x1;
v.x2 = x2 - x.x2;
v.x3