定义一个类vector,用运算符重载的方法实现向量的相加减及其输出
答案:1 悬赏:80 手机版
解决时间 2021-02-20 05:42
- 提问者网友:活着好累
- 2021-02-19 16:22
(为了方便编程,设向量均为三个元素且均为整数)。
最佳答案
- 五星知识达人网友:迷人又混蛋
- 2021-02-19 17:24
class CVector{
private:
int a,b,c;
public:
CVector(int A,int B,int C):a(A),b(B),c(C){};
~CVecotr(){};
friend CVector operator+(const CVector& left,const CVector& right);
friend CVector operator-(const CVector& left,const CVecor& right);
friend ostream& operator<<(ostream& out,const CVector& right);
};
CVector operator+(const CVector& left,const CVector& right){
return CVector(left.a+right.a,left.b+right.b,left.c+right.c);
}
CVector operator-(const CVector& left,const CVector& right){
return CVector(left.a-right.a,left.b-right.b,left.c-right.c);
}
ostream& operator<<(ostream& out,const CVector& right){
return out<<right.a<<right.b<<right.c<<endl;
}
基本模型大概就这样了
private:
int a,b,c;
public:
CVector(int A,int B,int C):a(A),b(B),c(C){};
~CVecotr(){};
friend CVector operator+(const CVector& left,const CVector& right);
friend CVector operator-(const CVector& left,const CVecor& right);
friend ostream& operator<<(ostream& out,const CVector& right);
};
CVector operator+(const CVector& left,const CVector& right){
return CVector(left.a+right.a,left.b+right.b,left.c+right.c);
}
CVector operator-(const CVector& left,const CVector& right){
return CVector(left.a-right.a,left.b-right.b,left.c-right.c);
}
ostream& operator<<(ostream& out,const CVector& right){
return out<<right.a<<right.b<<right.c<<endl;
}
基本模型大概就这样了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯