2023.4.24
1 //实验五任务二 2 #include <iostream> 3 using namespace std; 4 class vector3D 5 { 6 private: 7 float x,y,z; 8 public: 9 vector3D() 10 { 11 x = 0; 12 y = 0; 13 z = 0; 14 } 15 friend ostream& operator <<(ostream &cout,vector3D &temp); 16 friend void setValue(vector3D &v); 17 vector3D operator+(vector3D &v) 18 { 19 vector3D temp; 20 temp.x = this->x + v.x; 21 temp.y = this->y + v.y; 22 temp.z = this->z + v.z; 23 return temp; 24 } 25 vector3D operator-(vector3D &v) 26 { 27 vector3D temp; 28 temp.x = this->x - v.x; 29 temp.y = this->y - v.y; 30 temp.z = this->z - v.z; 31 return temp; 32 } 33 vector3D& operator* (int a) 34 { 35 this->x = a*this->x; 36 this->y = a*this->y; 37 this->z = a*this->z; 38 return *this; 39 } 40 }; 41 ostream& operator <<(ostream &cout,vector3D &v) 42 { 43 cout<<"("<<v.x<<","<<v.y<<","<<v.z<<")"; 44 return cout; 45 } 46 void setValue(vector3D &v) 47 { 48 cin>>v.x;cin>>v.y;cin>>v.z; 49 } 50 int main() 51 { 52 vector3D v1; 53 vector3D v2; 54 int num; 55 cin>>num; 56 if(num == 1) 57 {setValue(v1);} 58 else if(num == 2) 59 { 60 setValue(v1); 61 setValue(v2); 62 } 63 int a; 64 cin>>a; 65 vector3D v3; 66 v3 = v1 + v2; 67 cout<<v3<<endl; 68 v3 = v1 - v2; 69 cout<<v3<<endl; 70 v3 = v1*a; 71 cout<<v3<<endl; 72 return 0; 73 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?