SOJ.MyVector

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;

}



#include
         
         
          
          
#include
          
          
           
           
using namespace std;
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;
};
MyVector::MyVector(int a, int b, int c){
    x=a,y=b,z=c;
}
MyVector::MyVector(const MyVector & vec){
    x=vec.x,y=vec.y,z=vec.z;
};
void MyVector::display(){
    std::cout<
           
           
            
            <
            
            
             
             <
             
             
               < 
               
             
            
            
           
           
          
          
         
         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值