1001. MyVector
| ||
时间限制:1秒 内存限制:256兆
题目描述
有一个向量类MyVector,包括一个点的坐标位置x、y和z,实现其构造函数和三个友元函数,完成两个向量的加法、减法、点乘与叉乘运算。 MyVector的定义如下: class MyVector { public: MyVector(int = 0, int = 0, int = 0); MyVector(const MyVector &); void display(); friend MyVector add(MyVector &v1, MyVector &v2); friend MyVector sub(MyVector &v1, MyVector &v2); friend int dot(MyVector &v1, MyVector &v2); friend MyVector cross(MyVector &v1, MyVector &v2); private: int x, y, z; };
只需提交类声明,类成员函数与友元函数的实现。
样例输入
无
样例输出
(1,0,0)(-1,-3,0)(15,-10,-1)18
提示
主函数形式如下: int main() { MyVector a; MyVector b(1); MyVector c(2,3); MyVector d(3,4,5); MyVector e(c);
MyVector x = add(a, b); x.display(); MyVector y = sub(b, c); y.display(); MyVector z = cross(c, d); z.display(); int w = dot(d, e); cout << w << endl;
return 0; }
|